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-1612] libstdc++: Prefer const T to std::add_const_t<T> Date: Tue, 12 Jul 2022 08:39:09 +0000 (GMT) [thread overview] Message-ID: <20220712083909.6C8EA3858C53@sourceware.org> (raw) https://gcc.gnu.org/g:8be17e2ac73d43fd9781b842d47b0c3df2578756 commit r13-1612-g8be17e2ac73d43fd9781b842d47b0c3df2578756 Author: Jonathan Wakely <jwakely@redhat.com> Date: Thu Jul 7 12:27:08 2022 +0100 libstdc++: Prefer const T to std::add_const_t<T> For any typedef-name or template parameter, T, add_const_t<T> is equivalent to T const, so we can avoid instantiating the std::add_const class template and just say T const (or const T). This isn't true for a non-typedef like int&, where int& const would be ill-formed, but we shouldn't be using add_const_t<int&> anyway, because we know what that type is. The only place we need to continue using std::add_const is in the std::bind implementation where it's used as a template template parameter to be applied as a metafunction elsewhere. libstdc++-v3/ChangeLog: * include/bits/stl_iterator.h (__iter_to_alloc_t): Replace add_const_t with const-qualifier. * include/bits/utility.h (tuple_element<N, cv T>): Likewise for all cv-qualifiers. * include/std/type_traits (add_const, add_volatile): Replace typedef-declaration with using-declaration. (add_cv): Replace add_const and add_volatile with cv-qualifiers. * include/std/variant (variant_alternative<N, cv T>): Replace add_const_t, add_volatile_t and add_cv_t etc. with cv-qualifiers. Diff: --- libstdc++-v3/include/bits/stl_iterator.h | 11 +++++------ libstdc++-v3/include/bits/utility.h | 6 +++--- libstdc++-v3/include/std/type_traits | 9 +++------ libstdc++-v3/include/std/variant | 6 +++--- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index 12a89ab229f..049cb02a4c4 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -2536,19 +2536,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // of associative containers. template<typename _InputIterator> using __iter_key_t = remove_const_t< - typename iterator_traits<_InputIterator>::value_type::first_type>; + typename iterator_traits<_InputIterator>::value_type::first_type>; template<typename _InputIterator> - using __iter_val_t = - typename iterator_traits<_InputIterator>::value_type::second_type; + using __iter_val_t + = typename iterator_traits<_InputIterator>::value_type::second_type; template<typename _T1, typename _T2> struct pair; template<typename _InputIterator> - using __iter_to_alloc_t = - pair<add_const_t<__iter_key_t<_InputIterator>>, - __iter_val_t<_InputIterator>>; + using __iter_to_alloc_t + = pair<const __iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>>; #endif // __cpp_deduction_guides _GLIBCXX_END_NAMESPACE_VERSION diff --git a/libstdc++-v3/include/bits/utility.h b/libstdc++-v3/include/bits/utility.h index e0e40309a6d..6a192e27836 100644 --- a/libstdc++-v3/include/bits/utility.h +++ b/libstdc++-v3/include/bits/utility.h @@ -86,19 +86,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<size_t __i, typename _Tp> struct tuple_element<__i, const _Tp> { - typedef typename add_const<__tuple_element_t<__i, _Tp>>::type type; + using type = const __tuple_element_t<__i, _Tp>; }; template<size_t __i, typename _Tp> struct tuple_element<__i, volatile _Tp> { - typedef typename add_volatile<__tuple_element_t<__i, _Tp>>::type type; + using type = volatile __tuple_element_t<__i, _Tp>; }; template<size_t __i, typename _Tp> struct tuple_element<__i, const volatile _Tp> { - typedef typename add_cv<__tuple_element_t<__i, _Tp>>::type type; + using type = const volatile __tuple_element_t<__i, _Tp>; }; #if __cplusplus >= 201402L diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 2572d8edd69..e5f58bc2e3f 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -1577,20 +1577,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// add_const template<typename _Tp> struct add_const - { typedef _Tp const type; }; + { using type = _Tp const; }; /// add_volatile template<typename _Tp> struct add_volatile - { typedef _Tp volatile type; }; + { using type = _Tp volatile; }; /// add_cv template<typename _Tp> struct add_cv - { - typedef typename - add_const<typename add_volatile<_Tp>::type>::type type; - }; + { using type = _Tp const volatile; }; #if __cplusplus > 201103L diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant index 5ff1e3edcdf..f8f15665433 100644 --- a/libstdc++-v3/include/std/variant +++ b/libstdc++-v3/include/std/variant @@ -107,15 +107,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<size_t _Np, typename _Variant> struct variant_alternative<_Np, const _Variant> - { using type = add_const_t<variant_alternative_t<_Np, _Variant>>; }; + { using type = const variant_alternative_t<_Np, _Variant>; }; template<size_t _Np, typename _Variant> struct variant_alternative<_Np, volatile _Variant> - { using type = add_volatile_t<variant_alternative_t<_Np, _Variant>>; }; + { using type = volatile variant_alternative_t<_Np, _Variant>; }; template<size_t _Np, typename _Variant> struct variant_alternative<_Np, const volatile _Variant> - { using type = add_cv_t<variant_alternative_t<_Np, _Variant>>; }; + { using type = const volatile variant_alternative_t<_Np, _Variant>; }; inline constexpr size_t variant_npos = -1;
reply other threads:[~2022-07-12 8:39 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=20220712083909.6C8EA3858C53@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).