Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) std::all_of

 

std::all_of is an STL algorithm since the C++11 standard to check if all elements in a container satisfy a certain predicate.

 

 

#include <algorithm>
#include <cassert>

int main()
{
  //Create a std::vector with only positive values
  const std::vector<int> v = { 0,1,2,3,4,5 };
  //Assume all of these values are zero at least
  assert(std::all_of(v.begin(),v.end(),[](const int i){ return i >= 0; } ));
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict