[PATCH 2/2] libstdc++: Optimize is_reference
Jonathan Wakely
jwakely@redhat.com
Wed Sep 7 08:00:57 GMT 2022
On Wed, 7 Sept 2022 at 01:46, Patrick Palka via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> Instead of defining is_reference in terms of is_lvalue_reference
> and is_rvalue_reference, just define it directly.
>
> Tested on x86_64-pc-linux-gnu, does this look OK for trunk?
Yes, thanks (I already did this for the std::is_reference_v variable
template, but for some reason left this equivalent change in the local
branch where I was doing the traits refactoring).
> This reduces memory usage of join.cc by 1%.
Now that many of the variable templates have been optimized to avoid
instantiating class templates, I wonder if the <ranges> code (and
anything else that's only defined for C++17 or later) would benefit
from using foo_v<T> && bar_v<T> instead of __and_<foo<T>, bar<T>>.
With your improvements to __and_ maybe it doesn't make so much
difference.
>
> libstdc++-v3/ChangeLog:
>
> * include/std/type_traits (is_reference): Make the primary
> template derive from false_type. Define two partial
> specializations that derive from true_type.
> ---
> libstdc++-v3/include/std/type_traits | 13 +++++++++++--
> 1 file changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
> index b83e7257a9f..94e73eafd2f 100644
> --- a/libstdc++-v3/include/std/type_traits
> +++ b/libstdc++-v3/include/std/type_traits
> @@ -611,8 +611,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> /// is_reference
> template<typename _Tp>
> struct is_reference
> - : public __or_<is_lvalue_reference<_Tp>,
> - is_rvalue_reference<_Tp>>::type
> + : public false_type
> + { };
> +
> + template<typename _Tp>
> + struct is_reference<_Tp&>
> + : public true_type
> + { };
> +
> + template<typename _Tp>
> + struct is_reference<_Tp&&>
> + : public true_type
> { };
>
> /// is_arithmetic
> --
> 2.37.3.518.g79f2338b37
>
More information about the Libstdc++
mailing list