diff options
author | Eric Fiselier <eric@efcs.ca> | 2016-11-13 20:43:50 +0000 |
---|---|---|
committer | Eric Fiselier <eric@efcs.ca> | 2016-11-13 20:43:50 +0000 |
commit | 237158926663f31f2fcdb02cfedc0da19d6437f6 (patch) | |
tree | 5f9fec0af01b4b3779083b50c2c852fa41841f54 /libcxx/test/std/utilities/tuple | |
parent | 25d7683fe7b62e7ce5f3fc02a839a7572664beda (diff) | |
download | bcm5719-llvm-237158926663f31f2fcdb02cfedc0da19d6437f6.tar.gz bcm5719-llvm-237158926663f31f2fcdb02cfedc0da19d6437f6.zip |
Implement LWG 2770 - Make tuple_size<T> defined for all T
llvm-svn: 286779
Diffstat (limited to 'libcxx/test/std/utilities/tuple')
3 files changed, 30 insertions, 4 deletions
diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size.fail.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size.fail.cpp index 3f132e47b62..50c6f17efbe 100644 --- a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size.fail.cpp +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size.fail.cpp @@ -21,7 +21,7 @@ int main() { - (void)std::tuple_size<std::tuple<> &>::value; // expected-error {{implicit instantiation of undefined template}} - (void)std::tuple_size<int>::value; // expected-error {{implicit instantiation of undefined template}} - (void)std::tuple_size<std::tuple<>*>::value; // expected-error {{implicit instantiation of undefined template}} + (void)std::tuple_size<std::tuple<> &>::value; // expected-error {{no member named 'value'}} + (void)std::tuple_size<int>::value; // expected-error {{no member named 'value'}} + (void)std::tuple_size<std::tuple<>*>::value; // expected-error {{no member named 'value'}} } diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size.pass.cpp index 49b4215a195..40214f632e7 100644 --- a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size.pass.cpp +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size.pass.cpp @@ -18,19 +18,36 @@ // UNSUPPORTED: c++98, c++03 #include <tuple> +#include <utility> +#include <array> #include <type_traits> +template <class T, class = decltype(std::tuple_size<T>::value)> +constexpr bool has_value(int) { return true; } +template <class> constexpr bool has_value(long) { return false; } +template <class T> constexpr bool has_value() { return has_value<T>(0); } + + template <class T, std::size_t N> void test() { + static_assert(has_value<T>(), ""); static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, std::tuple_size<T> >::value), ""); + static_assert(has_value<const T>(), ""); static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, std::tuple_size<const T> >::value), ""); + static_assert(has_value<volatile T>(), ""); static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, std::tuple_size<volatile T> >::value), ""); + + static_assert(has_value<const volatile T>(), ""); static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, std::tuple_size<const volatile T> >::value), ""); + { + static_assert(!has_value<T &>(), ""); + static_assert(!has_value<T *>(), ""); + } } int main() @@ -39,4 +56,13 @@ int main() test<std::tuple<int>, 1>(); test<std::tuple<char, int>, 2>(); test<std::tuple<char, char*, int>, 3>(); + test<std::pair<int, void*>, 2>(); + test<std::array<int, 42>, 42>(); + { + static_assert(!has_value<void>(), ""); + static_assert(!has_value<void*>(), ""); + static_assert(!has_value<int>(), ""); + static_assert(!has_value<std::pair<int, int>*>(), ""); + static_assert(!has_value<std::array<int, 42>&>(), ""); + } } diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_v.fail.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_v.fail.cpp index 957a683b47f..700dd95c959 100644 --- a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_v.fail.cpp +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_v.fail.cpp @@ -22,5 +22,5 @@ int main() (void)std::tuple_size_v<std::tuple<> &>; // expected-note {{requested here}} (void)std::tuple_size_v<int>; // expected-note {{requested here}} (void)std::tuple_size_v<std::tuple<>*>; // expected-note {{requested here}} - // expected-error@tuple:* 3 {{implicit instantiation of undefined template}} + // expected-error@tuple:* 3 {{no member named 'value'}} } |