minmax.pass.cpp revision 9d9463a3555aa559884809b8a7fc842a3968193e
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
19template <class T>
20void
21test(const T& a, const T& b, const T& x, const T& y)
22{
23    std::pair<const T&, const T&> p = std::minmax(a, b);
24    assert(&p.first == &x);
25    assert(&p.second == &y);
26}
27
28int main()
29{
30    {
31    int x = 0;
32    int y = 0;
33    test(x, y, x, y);
34    test(y, x, y, x);
35    }
36    {
37    int x = 0;
38    int y = 1;
39    test(x, y, x, y);
40    test(y, x, x, y);
41    }
42    {
43    int x = 1;
44    int y = 0;
45    test(x, y, y, x);
46    test(y, x, y, x);
47    }
48#if _LIBCPP_STD_VER > 11
49    {
50//  Note that you can't take a reference to a local var, since
51//  it's address is not a compile-time constant.
52    constexpr static int x = 1;
53    constexpr static int y = 0;
54    constexpr auto p1 = std::minmax (x, y);
55    static_assert(p1.first  == y, "");
56    static_assert(p1.second == x, "");
57    constexpr auto p2 = std::minmax (y, x);
58    static_assert(p2.first  == y, "");
59    static_assert(p2.second == x, "");
60    }
61#endif
62}
63