• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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<LessThanComparable T>
13 //   pair<const T&, const T&>
14 //   minmax(const T& a, const T& b);
15 
16 #include <algorithm>
17 #include <cassert>
18 
19 #include "test_macros.h"
20 
21 template <class T>
22 void
test(const T & a,const T & b,const T & x,const T & y)23 test(const T& a, const T& b, const T& x, const T& y)
24 {
25     std::pair<const T&, const T&> p = std::minmax(a, b);
26     assert(&p.first == &x);
27     assert(&p.second == &y);
28 }
29 
main()30 int main()
31 {
32     {
33     int x = 0;
34     int y = 0;
35     test(x, y, x, y);
36     test(y, x, y, x);
37     }
38     {
39     int x = 0;
40     int y = 1;
41     test(x, y, x, y);
42     test(y, x, x, y);
43     }
44     {
45     int x = 1;
46     int y = 0;
47     test(x, y, y, x);
48     test(y, x, y, x);
49     }
50 #if TEST_STD_VER >= 14
51     {
52 //  Note that you can't take a reference to a local var, since
53 //  its address is not a compile-time constant.
54     constexpr static int x = 1;
55     constexpr static int y = 0;
56     constexpr auto p1 = std::minmax (x, y);
57     static_assert(p1.first  == y, "");
58     static_assert(p1.second == x, "");
59     constexpr auto p2 = std::minmax (y, x);
60     static_assert(p2.first  == y, "");
61     static_assert(p2.second == x, "");
62     }
63 #endif
64 }
65