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