0

What is the C++ way of checking if all values of bool vector (or bool array) are true ( do it with only 1 line like Python )

In Python, I can do

a = [true, true, true, false]
b = [true, true, true]

print(all(a)) # it will print false
print(all(b)) # it will print true

I can do it by creating a function to check it, but I want to know if it can be done by using a built-in library.

cigien
  • 57,834
  • 11
  • 73
  • 112
  • 5
    it's std::all_of. See here for examples https://en.cppreference.com/w/cpp/algorithm/all_any_none_of – mateeeeeee Nov 30 '20 at 13:16
  • 2
    @BasileStarynkevitch I don't follow. Why shouldn't there be one? Seems like a perfectly reasonable thing to want to be able to express conveniently. – cigien Nov 30 '20 at 13:17

0 Answers0