is_partitioned_until_example.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. Copyright (c) Alexander Zaitsev <zamazan4ik@gmail.by>, 2017
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. For more information, see http://www.boost.org
  6. */
  7. #include <vector>
  8. #include <functional>
  9. #include <iostream>
  10. #include <boost/algorithm/is_partitioned_until.hpp>
  11. namespace ba = boost::algorithm;
  12. bool isOdd(const int v1)
  13. {
  14. return v1 % 2 != 0;
  15. }
  16. struct isOddComp
  17. {
  18. bool operator()(const int v1) const
  19. {
  20. return v1 % 2 != 0;
  21. }
  22. };
  23. int main ( int /*argc*/, char * /*argv*/ [] )
  24. {
  25. std::vector<int> good{1, 2, 4};
  26. std::vector<int> bad{1, 2, 3};
  27. //Use custom function
  28. auto it1 = ba::is_partitioned_until(good.begin(), good.end(), isOdd);
  29. if(it1 == good.end())
  30. {
  31. std::cout << "The sequence is partitioned\n";
  32. }
  33. else
  34. {
  35. std::cout << "is_partitioned_until check failed here: " << *it1 << std::endl;
  36. }
  37. //Use custom comparator
  38. auto it2 = ba::is_partitioned_until(good.begin(), good.end(), isOddComp());
  39. if(it2 == good.end())
  40. {
  41. std::cout << "The sequence is partitioned\n";
  42. }
  43. else
  44. {
  45. std::cout << "is_partitioned_until check failed here: " << *it2 << std::endl;
  46. }
  47. auto it3 = ba::is_partitioned_until(bad, isOdd);
  48. if(it3 == bad.end())
  49. {
  50. std::cout << "The sequence is partitioned\n";
  51. }
  52. else
  53. {
  54. std::cout << "is_partitioned_until check failed here: " << *it3 << std::endl;
  55. }
  56. return 0;
  57. }