summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/algorithms
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2016-03-07 22:43:49 +0000
committerMarshall Clow <mclow.lists@gmail.com>2016-03-07 22:43:49 +0000
commit146c14ac33136ebff2714f4596f6d7db85d6b5e8 (patch)
tree20a0dcbeb4d5cf436b8e467cdcd4ccb602077b90 /libcxx/test/std/algorithms
parentb813e4d4ae0ab3bb3e7dbed0746180236ba52fbd (diff)
downloadbcm5719-llvm-146c14ac33136ebff2714f4596f6d7db85d6b5e8.tar.gz
bcm5719-llvm-146c14ac33136ebff2714f4596f6d7db85d6b5e8.zip
Implement P0025R0: 'An algorithm to clamp a value between a pair of boundary values' for C++17
llvm-svn: 262871
Diffstat (limited to 'libcxx/test/std/algorithms')
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.clamp/clamp.comp.pass.cpp61
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.clamp/clamp.pass.cpp60
2 files changed, 121 insertions, 0 deletions
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.clamp/clamp.comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.clamp/clamp.comp.pass.cpp
new file mode 100644
index 00000000000..e0d8127a7b7
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.clamp/clamp.comp.pass.cpp
@@ -0,0 +1,61 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <algorithm>
+// XFAIL: c++03, c++11, c++14
+
+// template<class T, class Compare>
+// const T&
+// clamp(const T& v, const T& lo, const T& hi, Compare comp);
+
+#include <algorithm>
+#include <functional>
+#include <cassert>
+
+template <class T, class C>
+void
+test(const T& v, const T& lo, const T& hi, C c, const T& x)
+{
+ assert(&std::clamp(v, lo, hi, c) == &x);
+}
+
+int main()
+{
+ {
+ int x = 0;
+ int y = 0;
+ int z = 0;
+ test(x, y, z, std::greater<int>(), x);
+ test(y, x, z, std::greater<int>(), y);
+ }
+ {
+ int x = 0;
+ int y = 1;
+ int z = -1;
+ test(x, y, z, std::greater<int>(), x);
+ test(y, x, z, std::greater<int>(), x);
+ }
+ {
+ int x = 1;
+ int y = 0;
+ int z = 0;
+ test(x, y, z, std::greater<int>(), y);
+ test(y, x, z, std::greater<int>(), y);
+ }
+#if _LIBCPP_STD_VER > 11
+ {
+ typedef int T;
+ constexpr T x = 1;
+ constexpr T y = 0;
+ constexpr T z = 0;
+ static_assert(std::clamp(x, y, z, std::greater<T>()) == y, "" );
+ static_assert(std::clamp(y, x, z, std::greater<T>()) == y, "" );
+ }
+#endif
+}
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.clamp/clamp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.clamp/clamp.pass.cpp
new file mode 100644
index 00000000000..838aaed9a3f
--- /dev/null
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.clamp/clamp.pass.cpp
@@ -0,0 +1,60 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <algorithm>
+// XFAIL: c++03, c++11, c++14
+
+// template<class T>
+// const T&
+// clamp(const T& v, const T& lo, const T& hi);
+
+#include <algorithm>
+#include <cassert>
+
+template <class T>
+void
+test(const T& a, const T& lo, const T& hi, const T& x)
+{
+ assert(&std::clamp(a, lo, hi) == &x);
+}
+
+int main()
+{
+ {
+ int x = 0;
+ int y = 0;
+ int z = 0;
+ test(x, y, z, x);
+ test(y, x, z, y);
+ }
+ {
+ int x = 0;
+ int y = 1;
+ int z = 2;
+ test(x, y, z, y);
+ test(y, x, z, y);
+ }
+ {
+ int x = 1;
+ int y = 0;
+ int z = 1;
+ test(x, y, z, x);
+ test(y, x, z, x);
+ }
+#if _LIBCPP_STD_VER > 11
+ {
+ typedef int T;
+ constexpr T x = 1;
+ constexpr T y = 0;
+ constexpr T z = 1;
+ static_assert(std::clamp(x, y, z) == x, "" );
+ static_assert(std::clamp(y, x, z) == x, "" );
+ }
+#endif
+}
OpenPOWER on IntegriCloud