]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/algorithms/alg.sorting/alg.min.max/minmax_comp.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / algorithms / alg.sorting / alg.min.max / minmax_comp.pass.cpp
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 #include "test_macros.h"
22
23 template <class T, class C>
24 void
25 test(const T& a, const T& b, C c, const T& x, const T& y)
26 {
27     std::pair<const T&, const T&> p = std::minmax(a, b, c);
28     assert(&p.first == &x);
29     assert(&p.second == &y);
30 }
31
32
33 int main()
34 {
35     {
36     int x = 0;
37     int y = 0;
38     test(x, y, std::greater<int>(), x, y);
39     test(y, x, std::greater<int>(), y, x);
40     }
41     {
42     int x = 0;
43     int y = 1;
44     test(x, y, std::greater<int>(), y, x);
45     test(y, x, std::greater<int>(), y, x);
46     }
47     {
48     int x = 1;
49     int y = 0;
50     test(x, y, std::greater<int>(), x, y);
51     test(y, x, std::greater<int>(), x, y);
52     }
53 #if TEST_STD_VER >= 14
54     {
55 //  Note that you can't take a reference to a local var, since
56 //  its address is not a compile-time constant.
57     constexpr static int x = 1;
58     constexpr static int y = 0;
59     constexpr auto p1 = std::minmax(x, y, std::greater<>());
60     static_assert(p1.first  == x, "");
61     static_assert(p1.second == y, "");
62     constexpr auto p2 = std::minmax(y, x, std::greater<>());
63     static_assert(p2.first  == x, "");
64     static_assert(p2.second == y, "");
65     }
66 #endif
67 }