any_all_none_of.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Range v3 library
  2. //
  3. // Copyright Jeff Garland 2017
  4. //
  5. // Use, modification and distribution is subject to the
  6. // Boost Software License, Version 1.0. (See accompanying
  7. // file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. // Project home: https://github.com/ericniebler/range-v3
  11. //
  12. //[any_all_none_of]]
  13. // Demonstrates any_of, all_of, none_of
  14. // output
  15. // vector: [6,2,3,4,5,6]
  16. // vector any_of is_six: true
  17. // vector all_of is_six: false
  18. // vector none_of is_six: false
  19. #include <range/v3/algorithm/all_of.hpp>
  20. #include <range/v3/algorithm/any_of.hpp>
  21. #include <range/v3/algorithm/for_each.hpp>
  22. #include <range/v3/algorithm/none_of.hpp>
  23. #include <range/v3/view/all.hpp>
  24. #include <iostream>
  25. #include <vector>
  26. using std::cout;
  27. auto is_six = [](int i) { return i == 6; };
  28. int
  29. main()
  30. {
  31. std::vector<int> v{6, 2, 3, 4, 5, 6};
  32. cout << std::boolalpha;
  33. cout << "vector: " << ranges::views::all(v) << '\n';
  34. cout << "vector any_of is_six: " << ranges::any_of(v, is_six) << '\n';
  35. cout << "vector all_of is_six: " << ranges::all_of(v, is_six) << '\n';
  36. cout << "vector none_of is_six: " << ranges::none_of(v, is_six) << '\n';
  37. }
  38. //[any_all_none_of]]