]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Add always_inline to ranges iterator ops and access functions
authorJonathan Wakely <jwakely@redhat.com>
Thu, 11 Sep 2025 08:34:02 +0000 (09:34 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Thu, 11 Sep 2025 13:38:58 +0000 (14:38 +0100)
commitf463e6bd8e84f12bde60f3e24e2d30da7fcda419
treee5c822beb60128dc2e883f98021d82f88c8a836d
parent9eab6c6f223808ceeebb55b5453c75782224cd9e
libstdc++: Add always_inline to ranges iterator ops and access functions

Most of the basis operations for ranges such as ranges::begin and
ranges::next are trivial one-line function bodies, so can be made
always_inline to reduce the abstraction penalty for -O0 code.

Now that we no longer need to support the -fconcepts-ts grammar, we can
also move some [[nodiscard]] attributes to the more natural position
before the function declaration, instead of between the declarator-id
and the function parameters, e.g. we can use:

  template<typename T> requires C<T> [[nodiscard]] auto operator()(T&&)

instead of:

  template<typename T> requires C<T> auto operator() [[nodiscard]] (T&&)

The latter form was necessary because -fconcepts-ts used a different
grammar for the requires-clause, parsing 'C<T>[[x]]' as a subscripting
operator with an ill-formed argument '[x]'. In the C++20 grammar you
would need to use parentheses to use a subscript in a constraint, so
without parentheses it's parsed as an attribute.

libstdc++-v3/ChangeLog:

* include/bits/ranges_base.h (__detail::__to_unsigned_like)
(__access::__possible_const_range, __access::__as_const)
(__distance_fn::operator(), __next_fn::operator())
(__prev_fn::operator()): Add always_inline attribute.
(_Begin::operator(), _End::operator(), _RBegin::operator())
(_REnd::operator(), _Size::operator(), _SSize::operator())
(_Empty::operator(), _Data::operator(), _SSize::operator()):
Likewise. Move nodiscard attribute to start of declaration.

Reviewed-by: Tomasz KamiƄski <tkaminsk@redhat.com>
libstdc++-v3/include/bits/ranges_base.h