diff options
Diffstat (limited to 'test/std/experimental/utilities/meta/meta.detect')
5 files changed, 224 insertions, 0 deletions
diff --git a/test/std/experimental/utilities/meta/meta.detect/detected_or.pass.cpp b/test/std/experimental/utilities/meta/meta.detect/detected_or.pass.cpp new file mode 100644 index 0000000000000..ffce814594784 --- /dev/null +++ b/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/test/std/experimental/utilities/meta/meta.detect/detected_t.pass.cpp b/test/std/experimental/utilities/meta/meta.detect/detected_t.pass.cpp new file mode 100644 index 0000000000000..136fb068be3c2 --- /dev/null +++ b/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/test/std/experimental/utilities/meta/meta.detect/is_detected.pass.cpp b/test/std/experimental/utilities/meta/meta.detect/is_detected.pass.cpp new file mode 100644 index 0000000000000..d8528a25161e2 --- /dev/null +++ b/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/test/std/experimental/utilities/meta/meta.detect/is_detected_convertible.pass.cpp b/test/std/experimental/utilities/meta/meta.detect/is_detected_convertible.pass.cpp new file mode 100644 index 0000000000000..8d1e0ae825d5a --- /dev/null +++ b/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/test/std/experimental/utilities/meta/meta.detect/is_detected_exact.pass.cpp b/test/std/experimental/utilities/meta/meta.detect/is_detected_exact.pass.cpp new file mode 100644 index 0000000000000..e9e5d8ce00566 --- /dev/null +++ b/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>(); +} |
