Steps to reproduce
#include <utility>
#include <functional>
namespace myspace
{
class BigThing // not really big, but just for illustration
{
public:
explicit BigThing(const int& v) : value(v) { }
int value;
bool operator == (const BigThing& r) const { return value == r.value; }
bool operator != (const BigThing& r) const { return value != r.value; }
bool operator < (const BigThing& r) const { return value < r.value; }
bool operator > (const BigThing& r) const { return value > r.value; }
private:
BigThing(const BigThing& );
BigThing& operator = (const BigThing& );
};
// a workaround for the non-conformant behavior of MSVC's minmax:
// even though it is in a different namespace,
// it sometimes lead to ambiguity with the problematic std::minmax in msvc,
// when unqualified name is used
// due to argument-dependent lookup (ADT), see below
template<typename T>
std::pair<const T&, const T&> minmax(const T& x, const T& y)
{
return y < x ?
std::pair<const T&, const T&>(y, x) :
std::pair<const T&, const T&>(x, y);
}
template<typename T, typename Pred>
std::pair<const T&, const T&> minmax(const T& x, const T& y, Pred comp)
{
return comp(y, x) ?
std::pair<const T&, const T&>(y, x) :
std::pair<const T&, const T&>(x, y);
}
template<typename T>
struct myless : public std::binary_function<T, T, bool>
{
bool operator() (const T& a, const T& b) const
{
return a < b;
}
};
}
using namespace myspace;
int main(int argc, char *argv[])
{
BigThing a(1);
BigThing b(2);
auto ret = std::minmax(a, b);
// compiler error: C2248
auto ret2 = minmax(a, b); // works ok.
auto ret3 = minmax(a, b, std::less<BigThing>());
// compiler error: C2668 (due to argument-dependent lookup)
auto ret4 = myspace::minmax(a, b); // works ok
return 0;
}
Actual results
The codes given in (Steps to reproduce) , which is definitely legal according to either standard or MSDN, should be built successfully.