C++ Logo

STD-PROPOSALS

Advanced search

Subject: Re: [std-proposals] Missing logical identity in <functional>
From: Miguel Ojeda (miguel.ojeda.sandonis_at_[hidden])
Date: 2019-08-25 07:49:52


On Sun, Aug 25, 2019 at 2:17 PM Alexander Klein via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> Hi all,
>
> the other day I was trying to test whether all of the bits in a
> std::vector< bool > were set or unset, but I couldn't come up with a
> really elegant solution using the logical operations in <functional>,
> because there seems to be no logical identity.
>
> In short, given
>
> std::vector< bool > v;
>
> I think it should be possible to write:
>
> const bool all_set = all_of ( v.cbegin(), v.cend(),
> std::logical_identity< bool >() );

An alternative in C++20 is:

    all_of(v.cbegin(), v.cend(), identity())

See [func.identity]

Cheers,
Miguel


STD-PROPOSALS list run by herb.sutter at gmail.com

Standard Proposals Archives on Google Groups