From c9fb0a85b68d1465ad1a88509a39190c27109c69 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Thu, 26 Sep 2019 17:08:44 +0100 Subject: [PATCH] Define std::to_array for Debug Mode * include/debug/array (to_array): Define for debug mode. From-SVN: r276155 --- libstdc++-v3/ChangeLog | 2 ++ libstdc++-v3/include/debug/array | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 83e3225..4b8bc7a 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,7 @@ 2019-09-26 Jonathan Wakely + * include/debug/array (to_array): Define for debug mode. + * include/bits/stl_pair.h (pair): Add _GLIBCXX20_CONSTEXPR to piecewise construction constructor, assignment operators, and swap. * include/std/tuple (pair::pair(piecewise_construct_t, tuple, tuple)): diff --git a/libstdc++-v3/include/debug/array b/libstdc++-v3/include/debug/array index 9e94e65..2f8eb84 100644 --- a/libstdc++-v3/include/debug/array +++ b/libstdc++-v3/include/debug/array @@ -314,6 +314,45 @@ namespace __debug static_assert(_Int < _Nm, "index is out of bounds"); return std::move(__debug::get<_Int>(__arr)); } + +#if __cplusplus > 201703L +#define __cpp_lib_to_array 201907L + + template + constexpr array, sizeof...(_Idx)> + __to_array(_Tp (&__a)[sizeof...(_Idx)], index_sequence<_Idx...>) + { + if constexpr (_Move) + return {{std::move(__a[_Idx])...}}; + else + return {{__a[_Idx]...}}; + } + + template + constexpr array, _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 __debug::__to_array(__a, make_index_sequence<_Nm>{}); + __builtin_unreachable(); // FIXME: see PR c++/91388 + } + + template + constexpr array, _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 __debug::__to_array<1>(__a, make_index_sequence<_Nm>{}); + __builtin_unreachable(); // FIXME: see PR c++/91388 + } +#endif // C++20 + } // namespace __debug _GLIBCXX_BEGIN_NAMESPACE_VERSION -- 2.7.4