libstdc++: Reduce header dependencies in and on <memory>
authorJonathan Wakely <jwakely@redhat.com>
Thu, 22 Oct 2020 17:42:03 +0000 (18:42 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 22 Oct 2020 17:42:03 +0000 (18:42 +0100)
By moving std::make_obj_using_allocator and the related "utility
functions for uses-allocator construction" to a new header, we can avoid
including the whole of <memory> in <scoped_allocator> and
<memory_resource>.

In order to simplify the implementation of those utility functions they
now use concepts unconditionally. They are no longer defined if
__cpp_concepts is not defined. To simplify the code that uses those
functions I've introduced a __cpp_lib_make_obj_using_allocator feature
test macro (not specified in the standard, which might be an oversight).
That allows the code in <memory_resource> and <scoped_allocator> to
check the feature test macro to decide whether to use the new utilities,
or fall back to the C++17 code.

At the same time, this reshuffles some of the headers included by
<memory> so that they are (mostly?) self-contained. It should no longer
be necessary to include other headers before <bits/shared_ptr.h> when
other parts of the library want to use std::shared_ptr without including
the whole of <memory>.

libstdc++-v3/ChangeLog:

* include/Makefile.am: Add new header.
* include/Makefile.in: Regenerate.
* include/bits/shared_ptr.h: Include <iosfwd>.
* include/bits/shared_ptr_base.h: Include required headers here
directly, instead of in <memory>.
* include/bits/uses_allocator_args.h: New file. Move utility
functions for uses-allocator construction from <memory> to here.
Only define the utility functions when concepts are available.
(__cpp_lib_make_obj_using_allocator): Define non-standard
feature test macro.
* include/std/condition_variable: Remove unused headers.
* include/std/future: Likewise.
* include/std/memory: Remove headers that are not needed
directly, and are now inclkuded where they're needed. Include
new <bits/uses_allocator_args.h> header.
* include/std/memory_resource: Include only the necessary
headers. Use new feature test macro to detect support for the
utility functions.
* include/std/scoped_allocator: Likewise.
* include/std/version (__cpp_lib_make_obj_using_allocator):
Define.

libstdc++-v3/include/Makefile.am
libstdc++-v3/include/Makefile.in
libstdc++-v3/include/bits/shared_ptr.h
libstdc++-v3/include/bits/shared_ptr_base.h
libstdc++-v3/include/bits/uses_allocator_args.h [new file with mode: 0644]
libstdc++-v3/include/std/condition_variable
libstdc++-v3/include/std/future
libstdc++-v3/include/std/memory
libstdc++-v3/include/std/memory_resource
libstdc++-v3/include/std/scoped_allocator
libstdc++-v3/include/std/version

index 28d273924ee0fa321ef58ea9379f7574a20ca20b..c90ac555e153e4bce4f91cd14448c30e89d38388 100644 (file)
@@ -222,6 +222,7 @@ bits_headers = \
        ${bits_srcdir}/unordered_map.h \
        ${bits_srcdir}/unordered_set.h \
        ${bits_srcdir}/uses_allocator.h \
+       ${bits_srcdir}/uses_allocator_args.h \
        ${bits_srcdir}/valarray_array.h \
        ${bits_srcdir}/valarray_array.tcc \
        ${bits_srcdir}/valarray_before.h \
index 2dfd8d2cb36a7e3cb0b33c76597529945c46eeed..aa751f62c4fe01da17bfe6bd3fd434ec920e7898 100644 (file)
@@ -568,6 +568,7 @@ bits_headers = \
        ${bits_srcdir}/unordered_map.h \
        ${bits_srcdir}/unordered_set.h \
        ${bits_srcdir}/uses_allocator.h \
+       ${bits_srcdir}/uses_allocator_args.h \
        ${bits_srcdir}/valarray_array.h \
        ${bits_srcdir}/valarray_array.tcc \
        ${bits_srcdir}/valarray_before.h \
index 0bfb525aae7833621c7d6558d5ed2fd0836996e8..92394c6a9e6fbaf99092c450e4ec0f2d0a549e6a 100644 (file)
@@ -49,6 +49,7 @@
 #ifndef _SHARED_PTR_H
 #define _SHARED_PTR_H 1
 
+#include <iosfwd>                // std::basic_ostream
 #include <bits/shared_ptr_base.h>
 
 namespace std _GLIBCXX_VISIBILITY(default)
index ca37f2bebd6e649ce8337719b0dd567495e1a393..a9e1c9bb1d5a2a70640cd494409a1c4f8486e0c2 100644 (file)
 
 #include <typeinfo>
 #include <bits/allocated_ptr.h>
+#include <bits/allocator.h>
+#include <bits/exception_defines.h>
+#include <bits/functional_hash.h>
 #include <bits/refwrap.h>
-#include <bits/stl_function.h>
+#include <bits/stl_function.h>  // std::less
+#include <bits/unique_ptr.h>
 #include <ext/aligned_buffer.h>
+#include <ext/atomicity.h>
+#include <ext/concurrence.h>
 #if __cplusplus > 201703L
 # include <compare>
 #endif
diff --git a/libstdc++-v3/include/bits/uses_allocator_args.h b/libstdc++-v3/include/bits/uses_allocator_args.h
new file mode 100644 (file)
index 0000000..2f10c8b
--- /dev/null
@@ -0,0 +1,227 @@
+// Utility functions for uses-allocator construction -*- C++ -*-
+
+// Copyright (C) 2019-2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+// <http://www.gnu.org/licenses/>.
+
+/*
+ * Copyright (c) 1997-1999
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation.  Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose.  It is provided "as is" without express or implied warranty.
+ *
+ */
+
+/** @file include/bits/uses_allocator_args.h
+ *  This is an internal header file, included by other library headers.
+ *  Do not attempt to use it directly. @headername{memory}
+ */
+
+#ifndef _USES_ALLOCATOR_ARGS
+#define _USES_ALLOCATOR_ARGS 1
+
+#pragma GCC system_header
+
+#if __cplusplus > 201703L && __cpp_concepts
+
+#include <new>                 // for placement operator new
+#include <tuple>               // for tuple, make_tuple, make_from_tuple
+#include <bits/stl_construct.h> // construct_at
+#include <bits/stl_pair.h>      // pair
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+  template<typename _Tp>
+    inline constexpr bool __is_pair = false;
+  template<typename _Tp, typename _Up>
+    inline constexpr bool __is_pair<pair<_Tp, _Up>> = true;
+  template<typename _Tp, typename _Up>
+    inline constexpr bool __is_pair<const pair<_Tp, _Up>> = true;
+
+  template<typename _Tp>
+    concept _Std_pair = __is_pair<_Tp>;
+
+/** @addtogroup allocators
+ *  @{
+ */
+
+// Not specified by C++20, used internally
+#define __cpp_lib_make_obj_using_allocator 201811L
+
+  template<typename _Tp, typename _Alloc, typename... _Args>
+    constexpr auto
+    uses_allocator_construction_args(const _Alloc& __a,
+                                    _Args&&... __args) noexcept
+    requires (! _Std_pair<_Tp>)
+    {
+      if constexpr (uses_allocator_v<remove_cv_t<_Tp>, _Alloc>)
+       {
+         if constexpr (is_constructible_v<_Tp, allocator_arg_t,
+                                          const _Alloc&, _Args...>)
+           {
+             return tuple<allocator_arg_t, const _Alloc&, _Args&&...>(
+                 allocator_arg, __a, std::forward<_Args>(__args)...);
+           }
+         else
+           {
+             static_assert(is_constructible_v<_Tp, _Args..., const _Alloc&>,
+                 "construction with an allocator must be possible"
+                 " if uses_allocator is true");
+
+             return tuple<_Args&&..., const _Alloc&>(
+                 std::forward<_Args>(__args)..., __a);
+           }
+       }
+      else
+       {
+         static_assert(is_constructible_v<_Tp, _Args...>);
+
+         return tuple<_Args&&...>(std::forward<_Args>(__args)...);
+       }
+    }
+
+  template<_Std_pair _Tp, typename _Alloc, typename _Tuple1, typename _Tuple2>
+    constexpr auto
+    uses_allocator_construction_args(const _Alloc& __a, piecewise_construct_t,
+                                    _Tuple1&& __x, _Tuple2&& __y) noexcept;
+
+  template<_Std_pair _Tp, typename _Alloc>
+    constexpr auto
+    uses_allocator_construction_args(const _Alloc&) noexcept;
+
+  template<_Std_pair _Tp, typename _Alloc, typename _Up, typename _Vp>
+    constexpr auto
+    uses_allocator_construction_args(const _Alloc&, _Up&&, _Vp&&) noexcept;
+
+  template<_Std_pair _Tp, typename _Alloc, typename _Up, typename _Vp>
+    constexpr auto
+    uses_allocator_construction_args(const _Alloc&,
+                                    const pair<_Up, _Vp>&) noexcept;
+
+  template<_Std_pair _Tp, typename _Alloc, typename _Up, typename _Vp>
+    constexpr auto
+    uses_allocator_construction_args(const _Alloc&, pair<_Up, _Vp>&&) noexcept;
+
+  template<_Std_pair _Tp, typename _Alloc, typename _Tuple1, typename _Tuple2>
+    constexpr auto
+    uses_allocator_construction_args(const _Alloc& __a, piecewise_construct_t,
+                                    _Tuple1&& __x, _Tuple2&& __y) noexcept
+    {
+      using _Tp1 = typename _Tp::first_type;
+      using _Tp2 = typename _Tp::second_type;
+
+      return std::make_tuple(piecewise_construct,
+         std::apply([&__a](auto&&... __args1) {
+             return std::uses_allocator_construction_args<_Tp1>(
+                 __a, std::forward<decltype(__args1)>(__args1)...);
+         }, std::forward<_Tuple1>(__x)),
+         std::apply([&__a](auto&&... __args2) {
+             return std::uses_allocator_construction_args<_Tp2>(
+                 __a, std::forward<decltype(__args2)>(__args2)...);
+         }, std::forward<_Tuple2>(__y)));
+    }
+
+  template<_Std_pair _Tp, typename _Alloc>
+    constexpr auto
+    uses_allocator_construction_args(const _Alloc& __a) noexcept
+    {
+      using _Tp1 = typename _Tp::first_type;
+      using _Tp2 = typename _Tp::second_type;
+
+      return std::make_tuple(piecewise_construct,
+         std::uses_allocator_construction_args<_Tp1>(__a),
+         std::uses_allocator_construction_args<_Tp2>(__a));
+    }
+
+  template<_Std_pair _Tp, typename _Alloc, typename _Up, typename _Vp>
+    constexpr auto
+    uses_allocator_construction_args(const _Alloc& __a, _Up&& __u, _Vp&& __v)
+      noexcept
+    {
+      using _Tp1 = typename _Tp::first_type;
+      using _Tp2 = typename _Tp::second_type;
+
+      return std::make_tuple(piecewise_construct,
+         std::uses_allocator_construction_args<_Tp1>(__a,
+           std::forward<_Up>(__u)),
+         std::uses_allocator_construction_args<_Tp2>(__a,
+           std::forward<_Vp>(__v)));
+    }
+
+  template<_Std_pair _Tp, typename _Alloc, typename _Up, typename _Vp>
+    constexpr auto
+    uses_allocator_construction_args(const _Alloc& __a,
+                                    const pair<_Up, _Vp>& __pr) noexcept
+    {
+      using _Tp1 = typename _Tp::first_type;
+      using _Tp2 = typename _Tp::second_type;
+
+      return std::make_tuple(piecewise_construct,
+         std::uses_allocator_construction_args<_Tp1>(__a, __pr.first),
+         std::uses_allocator_construction_args<_Tp2>(__a, __pr.second));
+    }
+
+  template<_Std_pair _Tp, typename _Alloc, typename _Up, typename _Vp>
+    constexpr auto
+    uses_allocator_construction_args(const _Alloc& __a,
+                                    pair<_Up, _Vp>&& __pr) noexcept
+    {
+      using _Tp1 = typename _Tp::first_type;
+      using _Tp2 = typename _Tp::second_type;
+
+      return std::make_tuple(piecewise_construct,
+         std::uses_allocator_construction_args<_Tp1>(__a,
+           std::move(__pr).first),
+         std::uses_allocator_construction_args<_Tp2>(__a,
+           std::move(__pr).second));
+    }
+
+  template<typename _Tp, typename _Alloc, typename... _Args>
+    inline _Tp
+    make_obj_using_allocator(const _Alloc& __a, _Args&&... __args)
+    {
+      return std::make_from_tuple<_Tp>(
+         std::uses_allocator_construction_args<_Tp>(__a,
+           std::forward<_Args>(__args)...));
+    }
+
+  template<typename _Tp, typename _Alloc, typename... _Args>
+    inline _Tp*
+    uninitialized_construct_using_allocator(_Tp* __p, const _Alloc& __a,
+                                           _Args&&... __args)
+    {
+      return std::apply([&](auto&&... __xs) {
+       return std::construct_at(__p, std::forward<decltype(__xs)>(__xs)...);
+      }, std::uses_allocator_construction_args<_Tp>(__a,
+       std::forward<_Args>(__args)...));
+    }
+// @}
+_GLIBCXX_END_NAMESPACE_VERSION
+} // namespace std
+#endif // C++20
+#endif // _USES_ALLOCATOR_ARGS
index 1abec546320bde8209419527e1e2d8a3833d55ac..7406fde6e4b40c8f8bf9e7c4d6dc4a99a8c941df 100644 (file)
 
 #include <bits/std_mutex.h>
 #include <bits/unique_lock.h>
-#include <ext/concurrence.h>
 #include <bits/alloc_traits.h>
-#include <bits/allocator.h>
-#include <bits/unique_ptr.h>
 #include <bits/shared_ptr.h>
 #include <bits/cxxabi_forced.h>
 
index a7466a32e03538dd2bc6dd67014e4cb028c0612d..3c2aaa1fab1994fd672377d96472b1094bda7fba 100644 (file)
 # include <bits/c++0x_warning.h>
 #else
 
-#include <mutex>
+#include <mutex>             // call_once
 #include <thread>
-#include <condition_variable>
+#include <condition_variable> // __at_thread_exit_elt
 #include <system_error>
 #include <atomic>
+#include <bits/allocated_ptr.h>
 #include <bits/atomic_futex.h>
-#include <bits/functexcept.h>
 #include <bits/invoke.h>
 #include <bits/unique_ptr.h>
 #include <bits/shared_ptr.h>
 #include <bits/std_function.h>
 #include <bits/uses_allocator.h>
-#include <bits/allocated_ptr.h>
 #include <ext/aligned_buffer.h>
 
 namespace std _GLIBCXX_VISIBILITY(default)
index aee7b050bd732a00eb89ae6a796f658dad8a1600..41ba74dd36f5879ac7707bebcef61530161f9b2c 100644 (file)
 #include <bits/stl_uninitialized.h>
 #include <bits/stl_tempbuf.h>
 #include <bits/stl_raw_storage_iter.h>
-#include <bits/ranges_uninitialized.h>
 
 #if __cplusplus >= 201103L
-#  include <exception>           // std::exception
-#  include <typeinfo>            // std::type_info in get_deleter
-#  include <iosfwd>              // std::basic_ostream
-#  include <ext/atomicity.h>
-#  include <ext/concurrence.h>
+#  include <type_traits>
 #  include <bits/align.h>
-#  include <bits/functexcept.h>
-#  include <bits/stl_function.h>  // std::less
 #  include <bits/uses_allocator.h>
 #  include <bits/alloc_traits.h>
-#  include <type_traits>
 #  include <debug/debug.h>
 #  include <bits/unique_ptr.h>
 #  include <bits/shared_ptr.h>
 #  include <bits/shared_ptr_atomic.h>
-#  if _GLIBCXX_USE_DEPRECATED
-#    include <backward/auto_ptr.h>
-#  endif
-#else
+#endif
+
+#if __cplusplus < 201103L || _GLIBCXX_USE_DEPRECATED
 #  include <backward/auto_ptr.h>
 #endif
 
-#if __cplusplus >= 201103L
-#include <cstdint>
 #if __cplusplus > 201703L
-# include <bit>                        // for has_single_bit
-# include <new>                        // for placement operator new
-# include <tuple>              // for tuple, make_tuple, make_from_tuple
+#  include <bits/ranges_uninitialized.h>
+#  include <bits/uses_allocator_args.h>
 #endif
+
+#if __cplusplus >= 201103L
 namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
@@ -140,210 +130,11 @@ inline pointer_safety
 get_pointer_safety() noexcept { return pointer_safety::relaxed; }
 // @}
 
-#if __cplusplus > 201703L
-  template<typename _Tp>
-    struct __is_pair : false_type { };
-  template<typename _Tp, typename _Up>
-    struct __is_pair<pair<_Tp, _Up>> : true_type { };
-  template<typename _Tp, typename _Up>
-    struct __is_pair<const pair<_Tp, _Up>> : true_type { };
-
-/** @addtogroup allocators
- *  @{
- */
-  template<typename _Tp, typename __ = _Require<__not_<__is_pair<_Tp>>>,
-          typename _Alloc, typename... _Args>
-    constexpr auto
-    __uses_alloc_args(const _Alloc& __a, _Args&&... __args) noexcept
-    {
-      if constexpr (uses_allocator_v<remove_cv_t<_Tp>, _Alloc>)
-       {
-         if constexpr (is_constructible_v<_Tp, allocator_arg_t,
-                                          const _Alloc&, _Args...>)
-           {
-             return tuple<allocator_arg_t, const _Alloc&, _Args&&...>(
-                 allocator_arg, __a, std::forward<_Args>(__args)...);
-           }
-         else
-           {
-             static_assert(is_constructible_v<_Tp, _Args..., const _Alloc&>,
-                 "construction with an allocator must be possible"
-                 " if uses_allocator is true");
-
-             return tuple<_Args&&..., const _Alloc&>(
-                 std::forward<_Args>(__args)..., __a);
-           }
-       }
-      else
-       {
-         static_assert(is_constructible_v<_Tp, _Args...>);
-
-         return tuple<_Args&&...>(std::forward<_Args>(__args)...);
-       }
-    }
-
-#if __cpp_concepts
-  template<typename _Tp>
-    concept _Std_pair = __is_pair<_Tp>::value;
-#endif
-
-// This is a temporary workaround until -fconcepts is implied by -std=gnu++2a
-#if __cpp_concepts
-# define _GLIBCXX_STD_PAIR_CONSTRAINT(T) _Std_pair T
-# define _GLIBCXX_STD_PAIR_CONSTRAINT_(T) _Std_pair T
-#else
-# define _GLIBCXX_STD_PAIR_CONSTRAINT(T) \
-      typename T, typename __ = _Require<__is_pair<T>>
-# define _GLIBCXX_STD_PAIR_CONSTRAINT_(T) typename T, typename
-#endif
-
-  template<typename _Tp,
-#if ! __cpp_concepts
-          typename __ = _Require<__not_<__is_pair<_Tp>>>,
-#endif
-          typename _Alloc, typename... _Args>
-    constexpr auto
-    uses_allocator_construction_args(const _Alloc& __a,
-                                    _Args&&... __args) noexcept
-#if __cpp_concepts
-    requires (! _Std_pair<_Tp>)
-#endif
-    {
-      return std::__uses_alloc_args<_Tp>(__a, std::forward<_Args>(__args)...);
-    }
-
-  template<_GLIBCXX_STD_PAIR_CONSTRAINT(_Tp), typename _Alloc,
-          typename _Tuple1, typename _Tuple2>
-    constexpr auto
-    uses_allocator_construction_args(const _Alloc& __a, piecewise_construct_t,
-                                    _Tuple1&& __x, _Tuple2&& __y) noexcept;
-
-  template<_GLIBCXX_STD_PAIR_CONSTRAINT(_Tp), typename _Alloc>
-    constexpr auto
-    uses_allocator_construction_args(const _Alloc&) noexcept;
-
-  template<_GLIBCXX_STD_PAIR_CONSTRAINT(_Tp), typename _Alloc,
-          typename _Up, typename _Vp>
-    constexpr auto
-    uses_allocator_construction_args(const _Alloc&, _Up&&, _Vp&&) noexcept;
-
-  template<_GLIBCXX_STD_PAIR_CONSTRAINT(_Tp), typename _Alloc,
-          typename _Up, typename _Vp>
-    constexpr auto
-    uses_allocator_construction_args(const _Alloc&,
-                                    const pair<_Up, _Vp>&) noexcept;
-
-  template<_GLIBCXX_STD_PAIR_CONSTRAINT(_Tp), typename _Alloc,
-          typename _Up, typename _Vp>
-    constexpr auto
-    uses_allocator_construction_args(const _Alloc&, pair<_Up, _Vp>&&) noexcept;
-
-  template<_GLIBCXX_STD_PAIR_CONSTRAINT_(_Tp), typename _Alloc,
-          typename _Tuple1, typename _Tuple2>
-    constexpr auto
-    uses_allocator_construction_args(const _Alloc& __a, piecewise_construct_t,
-                                    _Tuple1&& __x, _Tuple2&& __y) noexcept
-    {
-      using _Tp1 = typename _Tp::first_type;
-      using _Tp2 = typename _Tp::second_type;
-
-      return std::make_tuple(piecewise_construct,
-         std::apply([&__a](auto&&... __args1) {
-             return std::uses_allocator_construction_args<_Tp1>(
-                 __a, std::forward<decltype(__args1)>(__args1)...);
-         }, std::forward<_Tuple1>(__x)),
-         std::apply([&__a](auto&&... __args2) {
-             return std::uses_allocator_construction_args<_Tp2>(
-                 __a, std::forward<decltype(__args2)>(__args2)...);
-         }, std::forward<_Tuple2>(__y)));
-    }
-
-  template<_GLIBCXX_STD_PAIR_CONSTRAINT_(_Tp), typename _Alloc>
-    constexpr auto
-    uses_allocator_construction_args(const _Alloc& __a) noexcept
-    {
-      using _Tp1 = typename _Tp::first_type;
-      using _Tp2 = typename _Tp::second_type;
-
-      return std::make_tuple(piecewise_construct,
-         std::uses_allocator_construction_args<_Tp1>(__a),
-         std::uses_allocator_construction_args<_Tp2>(__a));
-    }
-
-  template<_GLIBCXX_STD_PAIR_CONSTRAINT_(_Tp), typename _Alloc,
-          typename _Up, typename _Vp>
-    constexpr auto
-    uses_allocator_construction_args(const _Alloc& __a, _Up&& __u, _Vp&& __v)
-      noexcept
-    {
-      using _Tp1 = typename _Tp::first_type;
-      using _Tp2 = typename _Tp::second_type;
-
-      return std::make_tuple(piecewise_construct,
-         std::uses_allocator_construction_args<_Tp1>(__a,
-           std::forward<_Up>(__u)),
-         std::uses_allocator_construction_args<_Tp2>(__a,
-           std::forward<_Vp>(__v)));
-    }
-
-  template<_GLIBCXX_STD_PAIR_CONSTRAINT_(_Tp), typename _Alloc,
-          typename _Up, typename _Vp>
-    constexpr auto
-    uses_allocator_construction_args(const _Alloc& __a,
-                                    const pair<_Up, _Vp>& __pr) noexcept
-    {
-      using _Tp1 = typename _Tp::first_type;
-      using _Tp2 = typename _Tp::second_type;
-
-      return std::make_tuple(piecewise_construct,
-         std::uses_allocator_construction_args<_Tp1>(__a, __pr.first),
-         std::uses_allocator_construction_args<_Tp2>(__a, __pr.second));
-    }
-
-  template<_GLIBCXX_STD_PAIR_CONSTRAINT_(_Tp), typename _Alloc,
-          typename _Up, typename _Vp>
-    constexpr auto
-    uses_allocator_construction_args(const _Alloc& __a,
-                                    pair<_Up, _Vp>&& __pr) noexcept
-    {
-      using _Tp1 = typename _Tp::first_type;
-      using _Tp2 = typename _Tp::second_type;
-
-      return std::make_tuple(piecewise_construct,
-         std::uses_allocator_construction_args<_Tp1>(__a,
-           std::move(__pr).first),
-         std::uses_allocator_construction_args<_Tp2>(__a,
-           std::move(__pr).second));
-    }
-
-  template<typename _Tp, typename _Alloc, typename... _Args>
-    inline _Tp
-    make_obj_using_allocator(const _Alloc& __a, _Args&&... __args)
-    {
-      return std::make_from_tuple<_Tp>(
-         std::uses_allocator_construction_args<_Tp>(__a,
-           std::forward<_Args>(__args)...));
-    }
-
-  template<typename _Tp, typename _Alloc, typename... _Args>
-    inline _Tp*
-    uninitialized_construct_using_allocator(_Tp* __p, const _Alloc& __a,
-                                           _Args&&... __args)
-    {
-      return std::apply([&](auto&&... __xs) {
-       return std::construct_at(__p, std::forward<decltype(__xs)>(__xs)...);
-      }, std::uses_allocator_construction_args<_Tp>(__a,
-       std::forward<_Args>(__args)...));
-    }
-// @}
-
-#endif // C++2a
-
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace
 #endif // C++11
 
-#if __cplusplus > 201402L
+#if __cplusplus >= 201703L
 // Parallel STL algorithms
 # if _PSTL_EXECUTION_POLICIES_DEFINED
 // If <execution> has already been included, pull in implementations
index 6491179a7c5fdb127730dcd3e8bab5da3715269d..350799ee3821386102cf3b9822c3d2bf5b01c162 100644 (file)
 
 #if __cplusplus >= 201703L
 
-#include <memory>                      // align, allocator_arg_t, __uses_alloc
-#include <utility>                     // pair, index_sequence
 #include <vector>                      // vector
 #include <cstddef>                     // size_t, max_align_t, byte
 #include <shared_mutex>                        // shared_mutex
-#include <bits/functexcept.h>
+#include <bits/align.h>                        // align
+#include <bits/functexcept.h>          // __throw_bad_array_new_length
+#include <bits/uses_allocator.h>       // __use_alloc
+#include <bits/uses_allocator_args.h>  // uninitialized_construct_using_alloc
 #include <ext/numeric_traits.h>
 #include <debug/assertions.h>
 
+#if ! __cpp_lib_make_obj_using_allocator
+# include <utility>                    // pair, index_sequence
+#endif
+
 namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
@@ -49,7 +54,7 @@ namespace pmr
 {
 #ifdef _GLIBCXX_HAS_GTHREADS
   // Header and all contents are present.
-# define __cpp_lib_memory_resource 201603
+# define __cpp_lib_memory_resource 201603L
 #else
   // The pmr::synchronized_pool_resource type is missing.
 # define __cpp_lib_memory_resource 1
@@ -231,7 +236,7 @@ namespace pmr
        }
 #endif // C++2a
 
-#if __cplusplus == 201703L
+#if ! __cpp_lib_make_obj_using_allocator
       template<typename _Tp1, typename... _Args>
        __attribute__((__nonnull__))
        typename __not_pair<_Tp1>::type
@@ -304,7 +309,7 @@ namespace pmr
                          forward_as_tuple(std::forward<_Up>(__pr.first)),
                          forward_as_tuple(std::forward<_Vp>(__pr.second)));
        }
-#else
+#else // make_obj_using_allocator
       template<typename _Tp1, typename... _Args>
        __attribute__((__nonnull__))
        void
@@ -334,6 +339,7 @@ namespace pmr
       using __uses_alloc1_ = __uses_alloc1<polymorphic_allocator>;
       using __uses_alloc2_ = __uses_alloc2<polymorphic_allocator>;
 
+#if ! __cpp_lib_make_obj_using_allocator
       template<typename _Ind, typename... _Args>
        static tuple<_Args&&...>
        _S_construct_p(__uses_alloc0, _Ind, tuple<_Args...>& __t)
@@ -354,6 +360,7 @@ namespace pmr
        _S_construct_p(__uses_alloc2_ __ua, index_sequence<_Ind...>,
                       tuple<_Args...>& __t)
        { return { std::get<_Ind>(std::move(__t))..., *__ua._M_a }; }
+#endif
 
       memory_resource* _M_resource;
     };
index 969b6d8e8c2aba99ab14c73851a09508e42c0caa..5f2fa5fac966aee4a72b0c290a8256e1e4c5acc4 100644 (file)
 # include <bits/c++0x_warning.h>
 #else
 
-#include <memory>
-#include <utility>
 #include <tuple>
 #include <bits/alloc_traits.h>
+#include <bits/stl_pair.h>
+#include <bits/uses_allocator.h>
+#if __cplusplus > 201703L
+# include <bits/uses_allocator_args.h>
+#endif
 
 namespace std _GLIBCXX_VISIBILITY(default)
 {
@@ -194,7 +197,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        using __outermost_alloc_traits
          = allocator_traits<typename __outermost_type<_Alloc>::type>;
 
-#if __cplusplus <= 201703
+#if ! __cpp_lib_make_obj_using_allocator
       template<typename _Tp, typename... _Args>
         void
         _M_construct(__uses_alloc0, _Tp* __p, _Args&&... __args)
@@ -226,7 +229,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                               std::forward<_Args>(__args)...,
                               inner_allocator());
         }
-#endif // C++17
+#endif // ! make_obj_using_allocator
 
       template<typename _Alloc>
         static _Alloc
@@ -364,7 +367,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       size_type max_size() const
       { return __traits::max_size(outer_allocator()); }
 
-#if __cplusplus <= 201703
+#if ! __cpp_lib_make_obj_using_allocator
       template<typename _Tp, typename... _Args>
        typename __not_pair<_Tp>::type
        construct(_Tp* __p, _Args&&... __args)
@@ -427,7 +430,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                    std::forward_as_tuple(std::forward<_Up>(__x.first)),
                    std::forward_as_tuple(std::forward<_Vp>(__x.second)));
        }
-#else // C++2a
+#else // make_obj_using_allocator
       template<typename _Tp, typename... _Args>
        __attribute__((__nonnull__))
        void
@@ -441,7 +444,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          uses_allocator_construction_args<_Tp>(inner_allocator(),
            std::forward<_Args>(__args)...));
        }
-#endif // C++2a
+#endif
 
       template<typename _Tp>
         void destroy(_Tp* __p)
@@ -464,7 +467,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                  const scoped_allocator_adaptor<_OutA2, _InA...>& __b) noexcept;
 
     private:
-#if __cplusplus <= 201703L
+#if ! __cpp_lib_make_obj_using_allocator
       template<typename _Ind, typename... _Args>
        tuple<_Args&&...>
        _M_construct_p(__uses_alloc0, _Ind, tuple<_Args...>& __t)
@@ -487,7 +490,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        {
          return { std::get<_Ind>(std::move(__t))..., inner_allocator() };
        }
-#endif // C++17
+#endif // ! make_obj_using_allocator
     };
 
   /// @related std::scoped_allocator_adaptor
index d5d42ed0a725ba1db264447b92fbcc7509e93e82..9c16f2c4e703af36eab115abd2c848a9c3e88cc0 100644 (file)
 #define __cpp_lib_map_try_emplace 201411
 #define __cpp_lib_math_special_functions 201603L
 #ifdef _GLIBCXX_HAS_GTHREADS
-# define __cpp_lib_memory_resource 201603
+# define __cpp_lib_memory_resource 201603L
 #else
 # define __cpp_lib_memory_resource 1
 #endif
 # define __cpp_lib_jthread 201911L
 #endif
 #define __cpp_lib_list_remove_return_type 201806L
+#if __cpp_lib_concepts
+# define __cpp_lib_make_obj_using_allocator 201811L
+#endif
 #define __cpp_lib_math_constants 201907L
 #define __cpp_lib_polymorphic_allocator 201902L
 #if __cpp_lib_concepts