Subject: Re: [std-proposals] Review Request: Proposal Ternary Right Fold Expression (P1012)
From: Arthur O'Dwyer (arthur.j.odwyer_at_[hidden])
Date: 2020-06-10 09:24:31
On Wed, Jun 10, 2020 at 2:06 AM Dvir Yitzchaki via Std-Proposals <
> you can get a similar behavior with operator||
> template <std::size_t... is>
> T test_impl(std::size_t j, std::index_sequence<is...>)
> T res;
> (void)( (j == is ? (res = f<is>(), true) : false) || ... || (throw
> std::range_error("Out of range"), false) );
> return res;
Unfortunately that requires `T` to be default-constructible and support
move-assignment, neither of which is necessarily true in modern code.
(Someone might even want to make `test_impl` return a *reference*.) Worse,
it requires all the `f<is>()` to have the same return type.
However, I agree, this should be mentioned in the paper, in a "Tony Table":
"here's how you can kinda do it in C++20, versus how I want to be able to
It would be useful to link to Jonathan MÃ¼ller's "Nifty Fold Expression
Tricks" https://foonathan.net/2020/05/fold-tricks/#content as well. He
gives this specific trick under the heading "Find the first element that
matches the predicate."
STD-PROPOSALS list run by email@example.com
Standard Proposals Archives on Google Groups