C++ Logo

std-proposals

Advanced search

Missing logical identity in <functional>

From: Alexander Klein <xelalex_maker_at_[hidden]>
Date: Sun, 25 Aug 2019 14:16:53 +0200
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 >() );

The current state of things in <functional> complicates this needlessly
by necessitating workarounds, some of which are obviously error-prone.

See the attachment for an example that will compile with g++ 4.8.4:

g++ -std=c++11 -pedantic all_bits.cpp

Would it be useful to write up a respective proposal?

Best regards,

 Alexander

Received on 2019-08-25 07:18:59