aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/std/array
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2021-07-22 14:48:27 +0100
committerJonathan Wakely <jwakely@redhat.com>2021-07-27 12:04:18 +0100
commit261d5a4a459bd49942e53bc83334ccc7154a09d5 (patch)
treedab5b16472ae1f39f8fc6b508b67333dd7c11c16 /libstdc++-v3/include/std/array
parentfcc7c6369f7fbf293f502d3d207a90b76cc2c62f (diff)
downloadgcc-261d5a4a459bd49942e53bc83334ccc7154a09d5.zip
gcc-261d5a4a459bd49942e53bc83334ccc7154a09d5.tar.gz
gcc-261d5a4a459bd49942e53bc83334ccc7154a09d5.tar.bz2
libstdc++: Reduce header dependencies on <array> and <utility>
This refactoring reduces the memory usage and compilation time to parse a number of headers that depend on std::pair, std::tuple or std::array. Previously the headers for these class templates were all intertwined, due to the common dependency on std::tuple_size, std::tuple_element and their std::get overloads. This decouples the headers by moving some parts of <utility> into a new <bits/utility.h> header. This means that <array> and <tuple> no longer need to include the whole of <utility>, and <tuple> no longer needs to include <array>. This decoupling benefits headers such as <thread> and <scoped_allocator> which only need std::tuple, and so no longer have to parse std::array. Some other headers such as <any>, <optional> and <variant> no longer need to include <utility> just for the std::in_place tag types, so do not have to parse the std::pair definitions. Removing direct uses of <utility> also means that the std::rel_ops namespace is not transitively declared by other headers. Signed-off-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: * include/Makefile.am: Add bits/utility.h header. * include/Makefile.in: Regenerate. * include/bits/utility.h: New file. * include/std/utility (tuple_size, tuple_element): Move to new header. * include/std/type_traits (__is_tuple_like_impl<tuple<T...>>): Move to <tuple>. (_Index_tuple, _Build_index_tuple, integer_sequence): Likewise. (in_place_t, in_place_index_t, in_place_type_t): Likewise. * include/bits/ranges_util.h: Include new header instead of <utility>. * include/bits/stl_pair.h (tuple_size, tuple_element): Move partial specializations for std::pair here. (get): Move overloads for std::pair here. * include/std/any: Include new header instead of <utility>. * include/std/array: Likewise. * include/std/memory_resource: Likewise. * include/std/optional: Likewise. * include/std/variant: Likewise. * include/std/tuple: Likewise. (__is_tuple_like_impl<tuple<T...>>): Move here. (get) Declare overloads for std::array. * include/std/version (__cpp_lib_tuples_by_type): Change type to long. * testsuite/20_util/optional/84601.cc: Include <utility>. * testsuite/20_util/specialized_algorithms/uninitialized_fill/constrained.cc: Likewise. * testsuite/23_containers/array/tuple_interface/get_neg.cc: Adjust dg-error line numbers. * testsuite/std/ranges/access/cbegin.cc: Include <utility>. * testsuite/std/ranges/access/cend.cc: Likewise. * testsuite/std/ranges/access/end.cc: Likewise. * testsuite/std/ranges/single_view.cc: Likewise.
Diffstat (limited to 'libstdc++-v3/include/std/array')
-rw-r--r--libstdc++-v3/include/std/array30
1 files changed, 13 insertions, 17 deletions
diff --git a/libstdc++-v3/include/std/array b/libstdc++-v3/include/std/array
index 0c6f33e..ea8d3cb 100644
--- a/libstdc++-v3/include/std/array
+++ b/libstdc++-v3/include/std/array
@@ -35,10 +35,14 @@
# include <bits/c++0x_warning.h>
#else
-#include <utility>
+#include <compare>
+#include <initializer_list>
+
+#include <type_traits>
#include <bits/functexcept.h>
#include <bits/stl_algobase.h>
-#include <bits/range_access.h>
+#include <bits/range_access.h> // std::begin, std::end etc.
+#include <bits/utility.h> // std::index_sequence, std::tuple_size
#include <debug/assertions.h>
namespace std _GLIBCXX_VISIBILITY(default)
@@ -428,28 +432,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Tuple interface to class template array.
- /// tuple_size
- template<typename _Tp>
- struct tuple_size;
-
/// Partial specialization for std::array
- template<typename _Tp, std::size_t _Nm>
+ template<typename _Tp, size_t _Nm>
struct tuple_size<array<_Tp, _Nm>>
- : public integral_constant<std::size_t, _Nm> { };
-
- /// tuple_element
- template<std::size_t _Int, typename _Tp>
- struct tuple_element;
+ : public integral_constant<size_t, _Nm> { };
/// Partial specialization for std::array
- template<std::size_t _Int, typename _Tp, std::size_t _Nm>
- struct tuple_element<_Int, array<_Tp, _Nm>>
+ template<size_t _Ind, typename _Tp, size_t _Nm>
+ struct tuple_element<_Ind, array<_Tp, _Nm>>
{
- static_assert(_Int < _Nm, "index is out of bounds");
- typedef _Tp type;
+ static_assert(_Ind < _Nm, "array index is in range");
+ using type = _Tp;
};
- template<typename _Tp, std::size_t _Nm>
+ template<typename _Tp, size_t _Nm>
struct __is_tuple_like_impl<array<_Tp, _Nm>> : true_type
{ };