1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 // <algorithm>
10
11 // template<LessThanComparable T>
12 // pair<const T&, const T&>
13 // minmax(const T& a, const T& b);
14
15 #include <algorithm>
16 #include <cassert>
17
18 #include "test_macros.h"
19
20 template <class T>
21 void
test(const T & a,const T & b,const T & x,const T & y)22 test(const T& a, const T& b, const T& x, const T& y)
23 {
24 std::pair<const T&, const T&> p = std::minmax(a, b);
25 assert(&p.first == &x);
26 assert(&p.second == &y);
27 }
28
main(int,char **)29 int main(int, char**)
30 {
31 {
32 int x = 0;
33 int y = 0;
34 test(x, y, x, y);
35 test(y, x, y, x);
36 }
37 {
38 int x = 0;
39 int y = 1;
40 test(x, y, x, y);
41 test(y, x, x, y);
42 }
43 {
44 int x = 1;
45 int y = 0;
46 test(x, y, y, x);
47 test(y, x, y, x);
48 }
49 #if TEST_STD_VER >= 14
50 {
51 // Note that you can't take a reference to a local var, since
52 // its address is not a compile-time constant.
53 constexpr static int x = 1;
54 constexpr static int y = 0;
55 constexpr auto p1 = std::minmax (x, y);
56 static_assert(p1.first == y, "");
57 static_assert(p1.second == x, "");
58 constexpr auto p2 = std::minmax (y, x);
59 static_assert(p2.first == y, "");
60 static_assert(p2.second == x, "");
61 }
62 #endif
63
64 return 0;
65 }
66