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 // const T&
14 // max(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)24 test(const T& a, const T& b, C c, const T& x)
25 {
26 assert(&std::max(a, b, c) == &x);
27 }
28
main(int,char **)29 int main(int, char**)
30 {
31 {
32 int x = 0;
33 int y = 0;
34 test(x, y, std::greater<int>(), x);
35 test(y, x, std::greater<int>(), y);
36 }
37 {
38 int x = 0;
39 int y = 1;
40 test(x, y, std::greater<int>(), x);
41 test(y, x, std::greater<int>(), x);
42 }
43 {
44 int x = 1;
45 int y = 0;
46 test(x, y, std::greater<int>(), y);
47 test(y, x, std::greater<int>(), y);
48 }
49 #if TEST_STD_VER >= 14
50 {
51 constexpr int x = 1;
52 constexpr int y = 0;
53 static_assert(std::max(x, y, std::greater<int>()) == y, "" );
54 static_assert(std::max(y, x, std::greater<int>()) == y, "" );
55 }
56 #endif
57
58 return 0;
59 }
60