C++ Logo

std-proposals

Advanced search

Re: Missing logical identity in <functional>

From: Miguel Ojeda <miguel.ojeda.sandonis_at_[hidden]>
Date: Sun, 25 Aug 2019 14:49:52 +0200
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

Received on 2019-08-25 07:52:07