Recently, I started using some standard functions provided by C++0x, which include std::minmax. I am currently using Microsoft Visual Studio 2010 (SP1).
According to the standard [alg.min.max], the function should be declared as
template<class T> std::pair<const T&, const T&> minmax(const T&, const T& );
In other words, it should return a pair of type std::pair<const T&, const T&>. This is also what is said in MSDN document. However, what the MSVC's actual implementation returns is of type std::pair<T, T>. The codes in the head file <xutility> (line 2107 - 2116) clearly confirms this.
Experienced programmers all understand the potential risk when you expect a reference but what you actually get is a temporary object. If T here is just an integer, it might be ok; but what if T is some big stuff. This would incur inefficiency, and in many cases even undefined behavior.
In addition, in the standard form, T need not to be copyable, but in current implementation provided by MSVC 2010 (SP1), the arguments are copied to the returned pair, implicitly enforcing the constraint that T is copyable.
Non-conformant behavior in such basic functions is very dangerous (more importantly, the actual implementation differs from what is documented in MSDN), which implicitly injects subtle bugs in innocent codes that may take hours to figure out.
Please fix this! Thank you.