Marshall Clow | 3e0808e | 2016-03-07 22:43:49 +0000 | [diff] [blame] | 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 | // XFAIL: c++03, c++11, c++14 |
| 12 | |
| 13 | // template<class T> |
| 14 | // const T& |
| 15 | // clamp(const T& v, const T& lo, const T& hi); |
| 16 | |
| 17 | #include <algorithm> |
| 18 | #include <cassert> |
| 19 | |
| 20 | template <class T> |
| 21 | void |
| 22 | test(const T& a, const T& lo, const T& hi, const T& x) |
| 23 | { |
| 24 | assert(&std::clamp(a, lo, hi) == &x); |
| 25 | } |
| 26 | |
| 27 | int main() |
| 28 | { |
| 29 | { |
| 30 | int x = 0; |
| 31 | int y = 0; |
| 32 | int z = 0; |
| 33 | test(x, y, z, x); |
| 34 | test(y, x, z, y); |
| 35 | } |
| 36 | { |
| 37 | int x = 0; |
| 38 | int y = 1; |
| 39 | int z = 2; |
| 40 | test(x, y, z, y); |
| 41 | test(y, x, z, y); |
| 42 | } |
| 43 | { |
| 44 | int x = 1; |
| 45 | int y = 0; |
| 46 | int z = 1; |
| 47 | test(x, y, z, x); |
| 48 | test(y, x, z, x); |
| 49 | } |
| 50 | #if _LIBCPP_STD_VER > 11 |
| 51 | { |
| 52 | typedef int T; |
| 53 | constexpr T x = 1; |
| 54 | constexpr T y = 0; |
| 55 | constexpr T z = 1; |
| 56 | static_assert(std::clamp(x, y, z) == x, "" ); |
| 57 | static_assert(std::clamp(y, x, z) == x, "" ); |
| 58 | } |
| 59 | #endif |
| 60 | } |