From patchwork Thu Oct 22 17:59:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1386369 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=ko++Cn2V; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CHFVk6k6Jz9sSG for ; Fri, 23 Oct 2020 04:59:26 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C28333986810; Thu, 22 Oct 2020 17:59:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C28333986810 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1603389564; bh=wtBKQ6iAHHOraswwgcK3uvdSao2wKIYMrTvh2Pl830s=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ko++Cn2VNTtuGCAXZAzn0BjSqm1CGxsDUyp2tZ7FvpxHoc1m/roGjakl7ycFoLGoK 50BhykFLincsgRI+yS9sXYweNN4R2lUz+R27WRMxLY2ardUD2RCO7gwqJFTtNeBBCM ycXkig5lzvdhdkj644dVk8p4zUyhYyQoBrV/Lmrc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id 93A52384C007 for ; Thu, 22 Oct 2020 17:59:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 93A52384C007 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-516-_BWlnmz3PHqCQQ1Fu1LvRw-1; Thu, 22 Oct 2020 13:59:16 -0400 X-MC-Unique: _BWlnmz3PHqCQQ1Fu1LvRw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D0A0A8049EF; Thu, 22 Oct 2020 17:59:15 +0000 (UTC) Received: from localhost (unknown [10.33.36.37]) by smtp.corp.redhat.com (Postfix) with ESMTP id 23C8A6EF42; Thu, 22 Oct 2020 17:59:14 +0000 (UTC) Date: Thu, 22 Oct 2020 18:59:14 +0100 To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed 1/2] libstdc++: Reduce header dependencies in and on Message-ID: <20201022175820.GA1313862@redhat.com> MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" 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 in and . 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 and 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 so that they are (mostly?) self-contained. It should no longer be necessary to include other headers before when other parts of the library want to use std::shared_ptr without including the whole of . libstdc++-v3/ChangeLog: * include/Makefile.am: Add new header. * include/Makefile.in: Regenerate. * include/bits/shared_ptr.h: Include . * include/bits/shared_ptr_base.h: Include required headers here directly, instead of in . * include/bits/uses_allocator_args.h: New file. Move utility functions for uses-allocator construction from 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 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. Tested powerpc64le-linux. Committed to trunk. commit b1e7c6fce15b8ad222f265df2537701407fd289e Author: Jonathan Wakely Date: Thu Oct 22 18:42:03 2020 libstdc++: Reduce header dependencies in and on 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 in and . 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 and 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 so that they are (mostly?) self-contained. It should no longer be necessary to include other headers before when other parts of the library want to use std::shared_ptr without including the whole of . libstdc++-v3/ChangeLog: * include/Makefile.am: Add new header. * include/Makefile.in: Regenerate. * include/bits/shared_ptr.h: Include . * include/bits/shared_ptr_base.h: Include required headers here directly, instead of in . * include/bits/uses_allocator_args.h: New file. Move utility functions for uses-allocator construction from 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 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. diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am index 28d273924ee..c90ac555e15 100644 --- a/libstdc++-v3/include/Makefile.am +++ b/libstdc++-v3/include/Makefile.am @@ -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 \ diff --git a/libstdc++-v3/include/bits/shared_ptr.h b/libstdc++-v3/include/bits/shared_ptr.h index 0bfb525aae7..92394c6a9e6 100644 --- a/libstdc++-v3/include/bits/shared_ptr.h +++ b/libstdc++-v3/include/bits/shared_ptr.h @@ -49,6 +49,7 @@ #ifndef _SHARED_PTR_H #define _SHARED_PTR_H 1 +#include // std::basic_ostream #include namespace std _GLIBCXX_VISIBILITY(default) diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h index ca37f2bebd6..a9e1c9bb1d5 100644 --- a/libstdc++-v3/include/bits/shared_ptr_base.h +++ b/libstdc++-v3/include/bits/shared_ptr_base.h @@ -51,9 +51,15 @@ #include #include +#include +#include +#include #include -#include +#include // std::less +#include #include +#include +#include #if __cplusplus > 201703L # include #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 index 00000000000..2f10c8b1745 --- /dev/null +++ b/libstdc++-v3/include/bits/uses_allocator_args.h @@ -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 +// . + +/* + * 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 // for placement operator new +#include // for tuple, make_tuple, make_from_tuple +#include // construct_at +#include // pair + +namespace std _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + template + inline constexpr bool __is_pair = false; + template + inline constexpr bool __is_pair> = true; + template + inline constexpr bool __is_pair> = true; + + template + concept _Std_pair = __is_pair<_Tp>; + +/** @addtogroup allocators + * @{ + */ + +// Not specified by C++20, used internally +#define __cpp_lib_make_obj_using_allocator 201811L + + template + constexpr auto + uses_allocator_construction_args(const _Alloc& __a, + _Args&&... __args) noexcept + requires (! _Std_pair<_Tp>) + { + if constexpr (uses_allocator_v, _Alloc>) + { + if constexpr (is_constructible_v<_Tp, allocator_arg_t, + const _Alloc&, _Args...>) + { + return tuple( + 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(__args1)...); + }, std::forward<_Tuple1>(__x)), + std::apply([&__a](auto&&... __args2) { + return std::uses_allocator_construction_args<_Tp2>( + __a, std::forward(__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 + 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 + 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(__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 diff --git a/libstdc++-v3/include/std/condition_variable b/libstdc++-v3/include/std/condition_variable index 1abec546320..7406fde6e4b 100644 --- a/libstdc++-v3/include/std/condition_variable +++ b/libstdc++-v3/include/std/condition_variable @@ -39,10 +39,7 @@ #include #include -#include #include -#include -#include #include #include diff --git a/libstdc++-v3/include/std/future b/libstdc++-v3/include/std/future index a7466a32e03..3c2aaa1fab1 100644 --- a/libstdc++-v3/include/std/future +++ b/libstdc++-v3/include/std/future @@ -35,19 +35,18 @@ # include #else -#include +#include // call_once #include -#include +#include // __at_thread_exit_elt #include #include +#include #include -#include #include #include #include #include #include -#include #include namespace std _GLIBCXX_VISIBILITY(default) diff --git a/libstdc++-v3/include/std/memory b/libstdc++-v3/include/std/memory index aee7b050bd7..41ba74dd36f 100644 --- a/libstdc++-v3/include/std/memory +++ b/libstdc++-v3/include/std/memory @@ -66,38 +66,28 @@ #include #include #include -#include #if __cplusplus >= 201103L -# include // std::exception -# include // std::type_info in get_deleter -# include // std::basic_ostream -# include -# include +# include # include -# include -# include // std::less # include # include -# include # include # include # include # include -# if _GLIBCXX_USE_DEPRECATED -# include -# endif -#else +#endif + +#if __cplusplus < 201103L || _GLIBCXX_USE_DEPRECATED # include #endif -#if __cplusplus >= 201103L -#include #if __cplusplus > 201703L -# include // for has_single_bit -# include // for placement operator new -# include // for tuple, make_tuple, make_from_tuple +# include +# include #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 - struct __is_pair : false_type { }; - template - struct __is_pair> : true_type { }; - template - struct __is_pair> : true_type { }; - -/** @addtogroup allocators - * @{ - */ - template>>, - typename _Alloc, typename... _Args> - constexpr auto - __uses_alloc_args(const _Alloc& __a, _Args&&... __args) noexcept - { - if constexpr (uses_allocator_v, _Alloc>) - { - if constexpr (is_constructible_v<_Tp, allocator_arg_t, - const _Alloc&, _Args...>) - { - return tuple( - 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 - 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> -# define _GLIBCXX_STD_PAIR_CONSTRAINT_(T) typename T, typename -#endif - - template>>, -#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(__args1)...); - }, std::forward<_Tuple1>(__x)), - std::apply([&__a](auto&&... __args2) { - return std::uses_allocator_construction_args<_Tp2>( - __a, std::forward(__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 - 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 - 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(__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 has already been included, pull in implementations diff --git a/libstdc++-v3/include/std/memory_resource b/libstdc++-v3/include/std/memory_resource index 6491179a7c5..350799ee382 100644 --- a/libstdc++-v3/include/std/memory_resource +++ b/libstdc++-v3/include/std/memory_resource @@ -33,15 +33,20 @@ #if __cplusplus >= 201703L -#include // align, allocator_arg_t, __uses_alloc -#include // pair, index_sequence #include // vector #include // size_t, max_align_t, byte #include // shared_mutex -#include +#include // align +#include // __throw_bad_array_new_length +#include // __use_alloc +#include // uninitialized_construct_using_alloc #include #include +#if ! __cpp_lib_make_obj_using_allocator +# include // 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 __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 __attribute__((__nonnull__)) void @@ -334,6 +339,7 @@ namespace pmr using __uses_alloc1_ = __uses_alloc1; using __uses_alloc2_ = __uses_alloc2; +#if ! __cpp_lib_make_obj_using_allocator template 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; }; diff --git a/libstdc++-v3/include/std/scoped_allocator b/libstdc++-v3/include/std/scoped_allocator index 969b6d8e8c2..5f2fa5fac96 100644 --- a/libstdc++-v3/include/std/scoped_allocator +++ b/libstdc++-v3/include/std/scoped_allocator @@ -36,10 +36,13 @@ # include #else -#include -#include #include #include +#include +#include +#if __cplusplus > 201703L +# include +#endif namespace std _GLIBCXX_VISIBILITY(default) { @@ -194,7 +197,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using __outermost_alloc_traits = allocator_traits::type>; -#if __cplusplus <= 201703 +#if ! __cpp_lib_make_obj_using_allocator template 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 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 __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 __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 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 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 diff --git a/libstdc++-v3/include/std/version b/libstdc++-v3/include/std/version index d5d42ed0a72..9c16f2c4e70 100644 --- a/libstdc++-v3/include/std/version +++ b/libstdc++-v3/include/std/version @@ -144,7 +144,7 @@ #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 @@ -217,6 +217,9 @@ # 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