public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-2704] libstdc++: Move allocator-related helpers to <bits/alloc_traits.h> Date: Fri, 16 Sep 2022 22:33:08 +0000 (GMT) [thread overview] Message-ID: <20220916223308.18D7B3854177@sourceware.org> (raw) https://gcc.gnu.org/g:7f4c37099a9f2415e00e94379c1206b3e9185c52 commit r13-2704-g7f4c37099a9f2415e00e94379c1206b3e9185c52 Author: Jonathan Wakely <jwakely@redhat.com> Date: Fri Sep 16 21:29:44 2022 +0100 libstdc++: Move allocator-related helpers to <bits/alloc_traits.h> The __alloc_swap and __shrink_to_fit_aux helpers are not specific to std::allocator, so don't belong in <bits/allocator.h>. This also simplifies enabling <memory> for freestanding, as now we can just omit the whole of <bits/allocator.h> for freestanding. libstdc++-v3/ChangeLog: * include/bits/alloc_traits.h (__alloc_swap) (__shrink_to_fit_aux): Move here, from ... * include/bits/allocator.h: ... here. * include/ext/alloc_traits.h: Do not include allocator.h. Diff: --- libstdc++-v3/include/bits/alloc_traits.h | 48 ++++++++++++++++++++++++++++++ libstdc++-v3/include/bits/allocator.h | 51 -------------------------------- libstdc++-v3/include/ext/alloc_traits.h | 3 -- 3 files changed, 48 insertions(+), 54 deletions(-) diff --git a/libstdc++-v3/include/bits/alloc_traits.h b/libstdc++-v3/include/bits/alloc_traits.h index f9ca37fd7d6..35bdf6ecf98 100644 --- a/libstdc++-v3/include/bits/alloc_traits.h +++ b/libstdc++-v3/include/bits/alloc_traits.h @@ -824,6 +824,54 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// @cond undocumented + // To implement Option 3 of DR 431. + template<typename _Alloc, bool = __is_empty(_Alloc)> + struct __alloc_swap + { static void _S_do_it(_Alloc&, _Alloc&) _GLIBCXX_NOEXCEPT { } }; + + template<typename _Alloc> + struct __alloc_swap<_Alloc, false> + { + static void + _S_do_it(_Alloc& __one, _Alloc& __two) _GLIBCXX_NOEXCEPT + { + // Precondition: swappable allocators. + if (__one != __two) + swap(__one, __two); + } + }; + +#if __cplusplus >= 201103L + template<typename _Tp, bool + = __or_<is_copy_constructible<typename _Tp::value_type>, + is_nothrow_move_constructible<typename _Tp::value_type>>::value> + struct __shrink_to_fit_aux + { static bool _S_do_it(_Tp&) noexcept { return false; } }; + + template<typename _Tp> + struct __shrink_to_fit_aux<_Tp, true> + { + _GLIBCXX20_CONSTEXPR + static bool + _S_do_it(_Tp& __c) noexcept + { +#if __cpp_exceptions + try + { + _Tp(__make_move_if_noexcept_iterator(__c.begin()), + __make_move_if_noexcept_iterator(__c.end()), + __c.get_allocator()).swap(__c); + return true; + } + catch(...) + { return false; } +#else + return false; +#endif + } + }; +#endif + /** * Destroy a range of objects using the supplied allocator. For * non-default allocators we do not optimize away invocation of diff --git a/libstdc++-v3/include/bits/allocator.h b/libstdc++-v3/include/bits/allocator.h index c39166e24fe..54f5acf85d7 100644 --- a/libstdc++-v3/include/bits/allocator.h +++ b/libstdc++-v3/include/bits/allocator.h @@ -279,57 +279,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Undefine. #undef __allocator_base - /// @cond undocumented - - // To implement Option 3 of DR 431. - template<typename _Alloc, bool = __is_empty(_Alloc)> - struct __alloc_swap - { static void _S_do_it(_Alloc&, _Alloc&) _GLIBCXX_NOEXCEPT { } }; - - template<typename _Alloc> - struct __alloc_swap<_Alloc, false> - { - static void - _S_do_it(_Alloc& __one, _Alloc& __two) _GLIBCXX_NOEXCEPT - { - // Precondition: swappable allocators. - if (__one != __two) - swap(__one, __two); - } - }; - -#if __cplusplus >= 201103L - template<typename _Tp, bool - = __or_<is_copy_constructible<typename _Tp::value_type>, - is_nothrow_move_constructible<typename _Tp::value_type>>::value> - struct __shrink_to_fit_aux - { static bool _S_do_it(_Tp&) noexcept { return false; } }; - - template<typename _Tp> - struct __shrink_to_fit_aux<_Tp, true> - { - _GLIBCXX20_CONSTEXPR - static bool - _S_do_it(_Tp& __c) noexcept - { -#if __cpp_exceptions - try - { - _Tp(__make_move_if_noexcept_iterator(__c.begin()), - __make_move_if_noexcept_iterator(__c.end()), - __c.get_allocator()).swap(__c); - return true; - } - catch(...) - { return false; } -#else - return false; -#endif - } - }; -#endif - /// @endcond - _GLIBCXX_END_NAMESPACE_VERSION } // namespace std diff --git a/libstdc++-v3/include/ext/alloc_traits.h b/libstdc++-v3/include/ext/alloc_traits.h index 1d7d9598cb2..c9547c7305c 100644 --- a/libstdc++-v3/include/ext/alloc_traits.h +++ b/libstdc++-v3/include/ext/alloc_traits.h @@ -32,9 +32,6 @@ #pragma GCC system_header # include <bits/alloc_traits.h> -#if __cplusplus < 201103L -# include <bits/allocator.h> // for __alloc_swap -#endif namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) {
reply other threads:[~2022-09-16 22:33 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220916223308.18D7B3854177@sourceware.org \ --to=redi@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).