1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <algorithm> 11 12 // template<class T, StrictWeakOrder<auto, T> Compare> 13 // requires !SameType<T, Compare> && CopyConstructible<Compare> 14 // pair<const T&, const T&> 15 // minmax(const T& a, const T& b, Compare comp); 16 17 #include <algorithm> 18 #include <functional> 19 #include <cassert> 20 21 template <class T, class C> 22 void 23 test(const T& a, const T& b, C c, const T& x, const T& y) 24 { 25 std::pair<const T&, const T&> p = std::minmax(a, b, c); 26 assert(&p.first == &x); 27 assert(&p.second == &y); 28 } 29 30 31 int main() 32 { 33 { 34 int x = 0; 35 int y = 0; 36 test(x, y, std::greater<int>(), x, y); 37 test(y, x, std::greater<int>(), y, x); 38 } 39 { 40 int x = 0; 41 int y = 1; 42 test(x, y, std::greater<int>(), y, x); 43 test(y, x, std::greater<int>(), y, x); 44 } 45 { 46 int x = 1; 47 int y = 0; 48 test(x, y, std::greater<int>(), x, y); 49 test(y, x, std::greater<int>(), x, y); 50 } 51 #if _LIBCPP_STD_VER > 11 52 { 53 // Note that you can't take a reference to a local var, since 54 // it's address is not a compile-time constant. 55 constexpr static int x = 1; 56 constexpr static int y = 0; 57 constexpr auto p1 = std::minmax(x, y, std::greater<>()); 58 static_assert(p1.first == x, ""); 59 static_assert(p1.second == y, ""); 60 constexpr auto p2 = std::minmax(y, x, std::greater<>()); 61 static_assert(p2.first == x, ""); 62 static_assert(p2.second == y, ""); 63 } 64 #endif 65 } 66