From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 99C3138582B7 for ; Tue, 12 Jul 2022 08:41:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 99C3138582B7 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-16-ecdjmGONMmOdF1_ha9ab3w-1; Tue, 12 Jul 2022 04:40:47 -0400 X-MC-Unique: ecdjmGONMmOdF1_ha9ab3w-1 Received: by mail-qk1-f199.google.com with SMTP id br43-20020a05620a462b00b006b5833f8132so4844894qkb.22 for ; Tue, 12 Jul 2022 01:40:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ijixgIIUpBOAsRrig9N9qMlnDqXmel9l6xBUYriwhK4=; b=IYEFyvj+TQ4gyW8oR4uUe9R2UMHGlfTGLXiYyyFWHduepzPWOkqUetQ59JH0xKFdiS Lmw1rgyl1Z7Qq3NFl9rY1mQLqhzJ1jbwVSDyxrcymolqjeMOF3NDy+O0awifW8FiGph2 5vzyTWCGu8e5HpQ9Wgq77GzozPPPoTfAF0fEkiKaQhRAw0VMCEJnKCvRdsVXj2laPMgw 4Wvq5LcNA2YzLYUNtuqiz44FK8b1eH9+zS99J6KoXKM1CKnfLG2qWp12orxyk84D+w4e Rz97TNZSee/QSBhx6drIiWr+25UShWZAY8UPld5hI4K2OhsaX/H/6FM23nOVItGeMQJK K1Zg== X-Gm-Message-State: AJIora8WUeqY/7IOWhEYAgrsI2nIzMNwi6S6/qReNoBcNoeShtcVSQ5c X3BEcgMb/q6qsZevP8WqBuA3N6wqB7QbP0ATajtCR/sbGtZUzX+OY38n30Cmlt8UUkrKpk5IRvd MykaA85I3gPMKk5MXJyTD821XiwiORlk= X-Received: by 2002:ac8:5e12:0:b0:31e:a396:19a7 with SMTP id h18-20020ac85e12000000b0031ea39619a7mr17126164qtx.491.1657615245752; Tue, 12 Jul 2022 01:40:45 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uygfg0qGl+4Nl4sTAhjXXZIIbMdPD5l70lRluD3wIluFyxZTEF4riUZZkyhWGUb7kyBZuWxrCMh9iU0yKzHWo= X-Received: by 2002:ac8:5e12:0:b0:31e:a396:19a7 with SMTP id h18-20020ac85e12000000b0031ea39619a7mr17126148qtx.491.1657615245295; Tue, 12 Jul 2022 01:40:45 -0700 (PDT) MIME-Version: 1.0 References: <20220707165442.1418451-1-jwakely@redhat.com> In-Reply-To: <20220707165442.1418451-1-jwakely@redhat.com> From: Jonathan Wakely Date: Tue, 12 Jul 2022 09:40:34 +0100 Message-ID: Subject: Re: [PATCH] libstdc++: Prefer const T to std::add_const_t To: Jonathan Wakely Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Jul 2022 08:41:05 -0000 On Thu, 7 Jul 2022 at 17:55, Jonathan Wakely via Libstdc++ wrote: > > Does anybody see a problem with this change? The point is to avoid > unnecessary class template instantiations. > > Tested aarch64-linux. Pushed to trunk now. > > -- >8 -- > > For any typedef-name or template parameter, T, add_const_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 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): 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): Replace > add_const_t, add_volatile_t and add_cv_t etc. with cv-qualifiers. > --- > 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 > using __iter_key_t = remove_const_t< > - typename iterator_traits<_InputIterator>::value_type::first_type>; > + typename iterator_traits<_InputIterator>::value_type::first_type>; > > template > - 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 > struct pair; > > template > - using __iter_to_alloc_t = > - pair>, > - __iter_val_t<_InputIterator>>; > + using __iter_to_alloc_t > + = pair, __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 > 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 > 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 > 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 > struct add_const > - { typedef _Tp const type; }; > + { using type = _Tp const; }; > > /// add_volatile > template > struct add_volatile > - { typedef _Tp volatile type; }; > + { using type = _Tp volatile; }; > > /// add_cv > template > struct add_cv > - { > - typedef typename > - add_const::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 > struct variant_alternative<_Np, const _Variant> > - { using type = add_const_t>; }; > + { using type = const variant_alternative_t<_Np, _Variant>; }; > > template > struct variant_alternative<_Np, volatile _Variant> > - { using type = add_volatile_t>; }; > + { using type = volatile variant_alternative_t<_Np, _Variant>; }; > > template > struct variant_alternative<_Np, const volatile _Variant> > - { using type = add_cv_t>; }; > + { using type = const volatile variant_alternative_t<_Np, _Variant>; }; > > inline constexpr size_t variant_npos = -1; > > -- > 2.36.1 >