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#include <utility>
18
19#include "test_macros.h"
20
21template <class T>
22void
23test(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
30int main(int, char**)
31{
32 {
33 int x = 0;
34 int y = 0;
35 test(a: x, b: 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 return 0;
66}
67

source code of libcxx/test/std/algorithms/alg.sorting/alg.min.max/minmax.pass.cpp