]> gcc.gnu.org Git - gcc.git/commit
libstdc++: Refine range adaptors' "simple extra args" mechanism [PR100940]
authorPatrick Palka <ppalka@redhat.com>
Thu, 17 Jun 2021 13:46:04 +0000 (09:46 -0400)
committerPatrick Palka <ppalka@redhat.com>
Fri, 18 Jun 2021 02:55:34 +0000 (22:55 -0400)
commitbc7a522548c37daf612c2ba4c44e9ea93548ed45
treea503037dbbd9985090b79bfba43f642b38ae7530
parent36b8b52a06c5021d60a81f2e619ebac938e426d1
libstdc++: Refine range adaptors' "simple extra args" mechanism [PR100940]

The _S_has_simple_extra_args mechanism is used to simplify forwarding
of range adaptor's extra arguments when perfect forwarding call wrapper
semantics isn't required for correctness, on a per-adaptor basis.
Both views::take and views::drop are flagged as such, but it turns out
perfect forwarding semantics are needed for these adaptors in some
contrived cases, e.g. when their extra argument is a move-only class
that's implicitly convertible to an integral type.

To fix this, we could just clear the flag for views::take/drop as with
views::split, but that'd come at the cost of acceptable diagnostics
for ill-formed uses of these adaptors (see PR100577).

This patch instead allows adaptors to parameterize their
_S_has_simple_extra_args flag according the types of the captured extra
arguments, so that we could conditionally disable perfect forwarding
semantics only when the types of the extra arguments permit it.  We
then use this finer-grained mechanism to safely disable perfect
forwarding semantics for views::take/drop when the extra argument is
integer-like, rather than incorrectly always disabling it.  Similarly,
for views::split, rather than always enabling perfect forwarding
semantics we now safely disable it when the extra argument is a scalar
or a view, and recover good diagnostics for these common cases.

PR libstdc++/100940

libstdc++-v3/ChangeLog:

* include/std/ranges (__adaptor::_RangeAdaptor): Document the
template form of _S_has_simple_extra_args.
(__adaptor::__adaptor_has_simple_extra_args): Add _Args template
parameter pack.  Try to treat _S_has_simple_extra_args as a
variable template parameterized by _Args.
(__adaptor::_Partial): Pass _Arg/_Args to the constraint
__adaptor_has_simple_extra_args.
(views::_Take::_S_has_simple_extra_args): Templatize according
to the type of the extra argument.
(views::_Drop::_S_has_simple_extra_args): Likewise.
(views::_Split::_S_has_simple_extra_args): Define.
* testsuite/std/ranges/adaptors/100577.cc (test01, test02):
Adjust after changes to _S_has_simple_extra_args mechanism.
(test03): Define.

(cherry picked from commit 0f4a2fb44dad6c9c140226fc19ed16109b85e6f4)
libstdc++-v3/include/std/ranges
libstdc++-v3/testsuite/std/ranges/adaptors/100577.cc
This page took 0.056466 seconds and 6 git commands to generate.