aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/std/array
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2019-08-08 11:18:53 +0100
committerJonathan Wakely <redi@gcc.gnu.org>2019-08-08 11:18:53 +0100
commitcb0de9b60cdc362915e06dfe8a373205d93b232d (patch)
treeeb8ea5a352572f604143dbf7c15af88900098bb8 /libstdc++-v3/include/std/array
parent0fddb1847019ceb570c6e0aea0ea779f1f9988cf (diff)
downloadgcc-cb0de9b60cdc362915e06dfe8a373205d93b232d.zip
gcc-cb0de9b60cdc362915e06dfe8a373205d93b232d.tar.gz
gcc-cb0de9b60cdc362915e06dfe8a373205d93b232d.tar.bz2
P0325R4 to_array from LFTS with updates
As an extension to what the standard requires, this also adds conditional noexcept-specifiers to the std::to_array functions. P0325R4 to_array from LFTS with updates * include/experimental/array (to_array): Qualify call to __to_array. * include/std/array (__cpp_lib_to_array, to_array): Define for C++20. * include/std/version (__cpp_lib_to_array): Likewise. * testsuite/23_containers/array/creation/1.cc: New test. * testsuite/23_containers/array/creation/2.cc: New test. * testsuite/23_containers/array/creation/3_neg.cc: New test. * testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc: Use zero for dg-error line number. From-SVN: r274209
Diffstat (limited to 'libstdc++-v3/include/std/array')
-rw-r--r--libstdc++-v3/include/std/array40
1 files changed, 39 insertions, 1 deletions
diff --git a/libstdc++-v3/include/std/array b/libstdc++-v3/include/std/array
index 31eff9e..a380f52 100644
--- a/libstdc++-v3/include/std/array
+++ b/libstdc++-v3/include/std/array
@@ -88,7 +88,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
* Sets support random access iterators.
*
* @tparam Tp Type of element. Required to be a complete type.
- * @tparam N Number of elements.
+ * @tparam Nm Number of elements.
*/
template<typename _Tp, std::size_t _Nm>
struct array
@@ -343,6 +343,44 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
return std::move(_GLIBCXX_STD_C::get<_Int>(__arr));
}
+#if __cplusplus > 201703L
+#define __cpp_lib_to_array 201907L
+
+ template<bool _Move = false, typename _Tp, size_t... _Idx>
+ constexpr array<remove_cv_t<_Tp>, sizeof...(_Idx)>
+ __to_array(_Tp (&__a)[sizeof...(_Idx)], index_sequence<_Idx...>)
+ {
+ if constexpr (_Move)
+ return {{std::move(__a[_Idx])...}};
+ else
+ return {{__a[_Idx]...}};
+ }
+
+ template<typename _Tp, size_t _Nm>
+ constexpr array<remove_cv_t<_Tp>, _Nm>
+ to_array(_Tp (&__a)[_Nm])
+ noexcept(is_nothrow_constructible_v<_Tp, _Tp&>)
+ {
+ static_assert(!is_array_v<_Tp>);
+ static_assert(is_constructible_v<_Tp, _Tp&>);
+ if constexpr (is_constructible_v<_Tp, _Tp&>)
+ return _GLIBCXX_STD_C::__to_array(__a, make_index_sequence<_Nm>{});
+ __builtin_unreachable(); // FIXME: see PR c++/91388
+ }
+
+ template<typename _Tp, size_t _Nm>
+ constexpr array<remove_cv_t<_Tp>, _Nm>
+ to_array(_Tp (&&__a)[_Nm])
+ noexcept(is_nothrow_move_constructible_v<_Tp>)
+ {
+ static_assert(!is_array_v<_Tp>);
+ static_assert(is_move_constructible_v<_Tp>);
+ if constexpr (is_move_constructible_v<_Tp>)
+ return _GLIBCXX_STD_C::__to_array<1>(__a, make_index_sequence<_Nm>{});
+ __builtin_unreachable(); // FIXME: see PR c++/91388
+ }
+#endif // C++20
+
_GLIBCXX_END_NAMESPACE_CONTAINER
} // namespace std