Source of all_of1a.cpp


  1: //all_of1a.cpp

  3: #include <iostream>
  4: #include <algorithm>
  5: #include <vector>
  6: using namespace std;

  8: int main()
  9: {
 10:     cout << "\nThis program illustrates the use of the STL all_of() "
 11:         "algorithm from <algorithm>\nto determine whether all "
 12:         "values in a vector of integers are even.";
 13:     cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');

 15:     int a[] = {2, 4, 6, 8, 10, 12, 14};
 16:     vector<int> v(begin(a), end(a));
 17:     cout << boolalpha;
 18:     cout << all_of(begin(v), end(v), [](int n){return n%2==0;}) << endl;
 19:     v.at(2) = 5;
 20:     cout << all_of(begin(v), end(v), [](int n){return n%2==0;}) << endl;
 21:     cout << "Press Enter to continue ... "; cin.ignore(80, '\n');
 22: }