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