From 46c719ddcd17a483554c491ba1db817c11f01f28 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Tue, 26 Feb 2019 16:07:03 +0000 Subject: [PATCH] Implement P1357: Traits for [Un]bounded Arrays; adopted in Kona llvm-svn: 354891 --- libcxx/include/type_traits | 29 +++++++++ .../meta.unary.comp/is_bounded_array.pass.cpp | 71 ++++++++++++++++++++++ .../meta.unary.comp/is_unbounded_array.pass.cpp | 71 ++++++++++++++++++++++ 3 files changed, 171 insertions(+) create mode 100644 libcxx/test/std/utilities/meta/meta.unary/meta.unary.comp/is_bounded_array.pass.cpp create mode 100644 libcxx/test/std/utilities/meta/meta.unary/meta.unary.comp/is_unbounded_array.pass.cpp diff --git a/libcxx/include/type_traits b/libcxx/include/type_traits index 37b7ca1..965ae7a 100644 --- a/libcxx/include/type_traits +++ b/libcxx/include/type_traits @@ -90,6 +90,9 @@ namespace std template struct remove_extent; template struct remove_all_extents; + template struct is_bounded_array; // C++20 + template struct is_unbounded_array; // C++20 + // Member introspection: template struct is_pod; template struct is_trivial; @@ -196,6 +199,12 @@ namespace std template using remove_all_extents_t = typename remove_all_extents::type; // C++14 + template + inline constexpr bool is_bounded_array_v + = is_bounded_array::value; // C++20 + inline constexpr bool is_unbounded_array_v + = is_unbounded_array::value; // C++20 + // pointer modifications: template using remove_pointer_t = typename remove_pointer::type; // C++14 @@ -1335,6 +1344,26 @@ template struct _LIBCPP_TEMPLATE_VIS remove_all_extents< template using remove_all_extents_t = typename remove_all_extents<_Tp>::type; #endif +#if _LIBCPP_STD_VER > 17 +// is_bounded_array + +template struct _LIBCPP_TEMPLATE_VIS is_bounded_array : false_type {}; +template struct _LIBCPP_TEMPLATE_VIS is_bounded_array<_Tp[_Np]> : true_type {}; + +template +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR +bool is_bounded_array_v = is_bounded_array<_Tp>::value; + +// is_unbounded_array + +template struct _LIBCPP_TEMPLATE_VIS is_unbounded_array : false_type {}; +template struct _LIBCPP_TEMPLATE_VIS is_unbounded_array<_Tp[]> : true_type {}; + +template +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR +bool is_unbounded_array_v = is_unbounded_array<_Tp>::value; +#endif + // decay template diff --git a/libcxx/test/std/utilities/meta/meta.unary/meta.unary.comp/is_bounded_array.pass.cpp b/libcxx/test/std/utilities/meta/meta.unary/meta.unary.comp/is_bounded_array.pass.cpp new file mode 100644 index 0000000..7a46b97 --- /dev/null +++ b/libcxx/test/std/utilities/meta/meta.unary/meta.unary.comp/is_bounded_array.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 + +// type_traits + +// is_bounded_array +// T is an array type of known bound ([dcl.array]) + +#include + +template +void test_array_imp() +{ + static_assert( B == std::is_bounded_array::value, "" ); + static_assert( B == std::is_bounded_array_v, "" ); +} + +template +void test_array() +{ + test_array_imp(); + test_array_imp(); + test_array_imp(); + test_array_imp(); +} + +typedef char array[3]; +typedef char incomplete_array[]; + +class incomplete_type; + +class Empty {}; +union Union {}; + +class Abstract +{ + virtual ~Abstract() = 0; +}; + +enum Enum {zero, one}; +typedef void (*FunctionPtr)(); + +int main(int, char**) +{ +// Non-array types + test_array(); + test_array(); + test_array(); + test_array(); + test_array(); + test_array(); + test_array(); + test_array(); + test_array(); + test_array(); + test_array(); + test_array(); + +// Array types + test_array(); + test_array(); + test_array(); + + return 0; +} diff --git a/libcxx/test/std/utilities/meta/meta.unary/meta.unary.comp/is_unbounded_array.pass.cpp b/libcxx/test/std/utilities/meta/meta.unary/meta.unary.comp/is_unbounded_array.pass.cpp new file mode 100644 index 0000000..3a561b0 --- /dev/null +++ b/libcxx/test/std/utilities/meta/meta.unary/meta.unary.comp/is_unbounded_array.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 + +// type_traits + +// is_unbounded_array +// T is an array type of unknown bound ([dcl.array]) + +#include + +template +void test_array_imp() +{ + static_assert( B == std::is_unbounded_array::value, "" ); + static_assert( B == std::is_unbounded_array_v, "" ); +} + +template +void test_array() +{ + test_array_imp(); + test_array_imp(); + test_array_imp(); + test_array_imp(); +} + +typedef char array[3]; +typedef char incomplete_array[]; + +class incomplete_type; + +class Empty {}; +union Union {}; + +class Abstract +{ + virtual ~Abstract() = 0; +}; + +enum Enum {zero, one}; +typedef void (*FunctionPtr)(); + +int main(int, char**) +{ +// Non-array types + test_array(); + test_array(); + test_array(); + test_array(); + test_array(); + test_array(); + test_array(); + test_array(); + test_array(); + test_array(); + test_array(); + test_array(); + +// Array types + test_array(); + test_array(); + test_array(); + + return 0; +} -- 2.7.4