blob: e0d8127a7b709aa8c7d0bf5c3c54cf071a2be9a3 [file] [log] [blame]
Marshall Clow3e0808e2016-03-07 22:43:49 +00001//===----------------------------------------------------------------------===//
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
21template <class T, class C>
22void
23test(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
28int 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}