Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Defs.h minmax() change/fix
Re: Defs.h minmax() change/fix [message #25373 is a reply to message #25325] Fri, 19 February 2010 16:52 Go to previous message
mirek is currently offline  mirek
Messages: 14256
Registered: November 2005
Ultimate Member
kohait00 wrote on Wed, 17 February 2010 04:24

yiy are right, the compiler warns
warning C4172: returning address of local variable or temporary

using a
s = min(max(a, b), c);

//instead of

s = minmax(a, b, c);

does not produce this warning. i still dont get why.

maybe to have a

#define minmax(x, _min, max) min(max(x, _min), _max)

is a choice.

or at least
template <class T>
inline T minmax(const T& x, const T& _min, const T& _max) { return min(max(x, _min), _max); }

reducing the need of object copy by 60% Smile (roughly)

dont know it this is that much of speed saving, but using refs instead of temp copies is better anyway, isnt it?



In this case, I believe there will be no difference in code generated in most cases. It is inline after all. And in fact, it is used on fundamental types 90% of time.

Mirek
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Uuid formating with dashes
Next Topic: ERROR: EXCEPTION_ACCESS_VIOLATION IN CORE ON DEBUGGING!
Goto Forum:
  


Current Time: Wed May 07 14:01:21 CEST 2025

Total time taken to generate the page: 0.04693 seconds