summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2016-11-26 15:49:40 +0000
committerMarshall Clow <mclow.lists@gmail.com>2016-11-26 15:49:40 +0000
commit3b3352dead5c00ec49ff619607e5507c8a7314e2 (patch)
tree910ea40f3a708df3e2b9ab61eab469419596dfda /libcxx/test/std
parent8bd69b7ed9fb4e9d815326b3cfd507584e98c7ad (diff)
downloadbcm5719-llvm-3b3352dead5c00ec49ff619607e5507c8a7314e2.tar.gz
bcm5719-llvm-3b3352dead5c00ec49ff619607e5507c8a7314e2.zip
Implement the 'detection idiom' from LFTS v2
llvm-svn: 287981
Diffstat (limited to 'libcxx/test/std')
-rw-r--r--libcxx/test/std/experimental/utilities/meta/meta.detect/detected_or.pass.cpp40
-rw-r--r--libcxx/test/std/experimental/utilities/meta/meta.detect/detected_t.pass.cpp48
-rw-r--r--libcxx/test/std/experimental/utilities/meta/meta.detect/is_detected.pass.cpp37
-rw-r--r--libcxx/test/std/experimental/utilities/meta/meta.detect/is_detected_convertible.pass.cpp50
-rw-r--r--libcxx/test/std/experimental/utilities/meta/meta.detect/is_detected_exact.pass.cpp49
5 files changed, 224 insertions, 0 deletions
diff --git a/libcxx/test/std/experimental/utilities/meta/meta.detect/detected_or.pass.cpp b/libcxx/test/std/experimental/utilities/meta/meta.detect/detected_or.pass.cpp
new file mode 100644
index 00000000000..ffce8145947
--- /dev/null
+++ b/libcxx/test/std/experimental/utilities/meta/meta.detect/detected_or.pass.cpp
@@ -0,0 +1,40 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03, c++11
+// <experimental/type_traits>
+
+#include <experimental/type_traits>
+#include <string>
+
+#include "test_macros.h"
+
+namespace ex = std::experimental;
+
+template <typename T>
+ using hasFoo = typename T::Foo;
+
+struct yesFoo {
+ using Foo = int;
+};
+
+struct noFoo {
+};
+
+
+template <typename T, typename Res>
+void test() {
+ static_assert( std::is_same<Res, typename ex::detected_or <double, hasFoo, T>::type>::value, "" );
+ static_assert( std::is_same<Res, typename ex::detected_or_t<double, hasFoo, T> >::value, "" );
+}
+
+int main () {
+ test<yesFoo, int>();
+ test<noFoo, double>();
+}
diff --git a/libcxx/test/std/experimental/utilities/meta/meta.detect/detected_t.pass.cpp b/libcxx/test/std/experimental/utilities/meta/meta.detect/detected_t.pass.cpp
new file mode 100644
index 00000000000..136fb068be3
--- /dev/null
+++ b/libcxx/test/std/experimental/utilities/meta/meta.detect/detected_t.pass.cpp
@@ -0,0 +1,48 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03, c++11
+// <experimental/type_traits>
+
+#include <experimental/type_traits>
+#include <string>
+
+#include "test_macros.h"
+
+namespace ex = std::experimental;
+
+template <typename T>
+ using callFoo = decltype(std::declval<T&>().Foo());
+
+struct yesFoo {
+ int Foo() { return 0; }
+};
+
+struct noFoo {
+};
+
+struct wrongFoo {
+ std::string Foo() { return ""; }
+};
+
+struct convertibleFoo {
+ long Foo() { return 0; }
+};
+
+
+template <typename T, typename Res>
+void test() {
+ static_assert( std::is_same<Res, typename ex::detected_t<callFoo, T>>::value, "" );
+}
+
+int main () {
+ test<yesFoo, int>();
+ test<noFoo, ex::nonesuch>(); // lookup failure returns nonesuch
+ test<wrongFoo, std::string>();
+}
diff --git a/libcxx/test/std/experimental/utilities/meta/meta.detect/is_detected.pass.cpp b/libcxx/test/std/experimental/utilities/meta/meta.detect/is_detected.pass.cpp
new file mode 100644
index 00000000000..d8528a25161
--- /dev/null
+++ b/libcxx/test/std/experimental/utilities/meta/meta.detect/is_detected.pass.cpp
@@ -0,0 +1,37 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03, c++11
+// <experimental/type_traits>
+
+#include <experimental/type_traits>
+#include <string>
+
+#include "test_macros.h"
+
+namespace ex = std::experimental;
+
+template <typename T>
+ using copy_assign_t = decltype(std::declval<T&>() = std::declval<T const &>());
+
+struct not_assignable {
+ not_assignable & operator=(const not_assignable&) = delete;
+};
+
+template <typename T, bool b>
+void test() {
+ static_assert( b == ex::is_detected <copy_assign_t, T>::value, "" );
+ static_assert( b == ex::is_detected_v<copy_assign_t, T>, "" );
+}
+
+int main () {
+ test<int, true>();
+ test<std::string, true>();
+ test<not_assignable, false>();
+}
diff --git a/libcxx/test/std/experimental/utilities/meta/meta.detect/is_detected_convertible.pass.cpp b/libcxx/test/std/experimental/utilities/meta/meta.detect/is_detected_convertible.pass.cpp
new file mode 100644
index 00000000000..8d1e0ae825d
--- /dev/null
+++ b/libcxx/test/std/experimental/utilities/meta/meta.detect/is_detected_convertible.pass.cpp
@@ -0,0 +1,50 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03, c++11
+// <experimental/type_traits>
+
+#include <experimental/type_traits>
+#include <string>
+
+#include "test_macros.h"
+
+namespace ex = std::experimental;
+
+template <typename T>
+ using callFoo = decltype(std::declval<T&>().Foo());
+
+struct yesFoo {
+ int Foo() { return 0; }
+};
+
+struct noFoo {
+};
+
+struct wrongFoo {
+ std::string Foo() { return ""; }
+};
+
+struct convertibleFoo {
+ long Foo() { return 0; }
+};
+
+
+template <typename T, bool b>
+void test() {
+ static_assert( b == ex::is_detected_convertible <int, callFoo, T>::value, "" );
+ static_assert( b == ex::is_detected_convertible_v<int, callFoo, T>, "" );
+}
+
+int main () {
+ test<yesFoo, true>();
+ test<noFoo, false>();
+ test<wrongFoo, false>();
+ test<convertibleFoo, true>();
+}
diff --git a/libcxx/test/std/experimental/utilities/meta/meta.detect/is_detected_exact.pass.cpp b/libcxx/test/std/experimental/utilities/meta/meta.detect/is_detected_exact.pass.cpp
new file mode 100644
index 00000000000..e9e5d8ce005
--- /dev/null
+++ b/libcxx/test/std/experimental/utilities/meta/meta.detect/is_detected_exact.pass.cpp
@@ -0,0 +1,49 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03, c++11
+// <experimental/type_traits>
+
+#include <experimental/type_traits>
+#include <string>
+
+#include "test_macros.h"
+
+namespace ex = std::experimental;
+
+template <typename T>
+ using callFoo = decltype(std::declval<T&>().Foo());
+
+struct yesFoo {
+ int Foo() { return 0; }
+};
+
+struct noFoo {
+};
+
+struct wrongFoo {
+ std::string Foo() { return ""; }
+};
+
+struct convertibleFoo {
+ long Foo() { return 0; }
+};
+
+template <typename T, bool b>
+void test() {
+ static_assert( b == ex::is_detected_exact <int, callFoo, T>::value, "" );
+ static_assert( b == ex::is_detected_exact_v<int, callFoo, T>, "" );
+}
+
+int main () {
+ test<yesFoo, true>();
+ test<noFoo, false>();
+ test<wrongFoo, false>();
+ test<convertibleFoo, false>();
+}
OpenPOWER on IntegriCloud