| 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 | // const T& |
| 13 | // max(const T& a, const T& b); |
| 14 | |
| 15 | #include <algorithm> |
| 16 | #include <cassert> |
| 17 | |
| 18 | #include "test_macros.h" |
| 19 | |
| 20 | template <class T> |
| 21 | void |
| 22 | test(const T& a, const T& b, const T& x) |
| 23 | { |
| 24 | assert(&std::max(a, b) == &x); |
| 25 | } |
| 26 | |
| 27 | int main(int, char**) |
| 28 | { |
| 29 | { |
| 30 | int x = 0; |
| 31 | int y = 0; |
| 32 | test(a: x, b: y, x); |
| 33 | test(y, x, y); |
| 34 | } |
| 35 | { |
| 36 | int x = 0; |
| 37 | int y = 1; |
| 38 | test(x, y, y); |
| 39 | test(y, x, y); |
| 40 | } |
| 41 | { |
| 42 | int x = 1; |
| 43 | int y = 0; |
| 44 | test(x, y, x); |
| 45 | test(y, x, x); |
| 46 | } |
| 47 | #if TEST_STD_VER >= 14 |
| 48 | { |
| 49 | constexpr int x = 1; |
| 50 | constexpr int y = 0; |
| 51 | static_assert(std::max(x, y) == x, "" ); |
| 52 | static_assert(std::max(y, x) == x, "" ); |
| 53 | } |
| 54 | #endif |
| 55 | |
| 56 | return 0; |
| 57 | } |
| 58 | |