adjacent_filtered_example.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Boost.Range library
  2. //
  3. // Copyright Neil Groves 2009. Use, modification and
  4. // distribution is subject to the Boost Software License, Version
  5. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. //
  9. // For more information, see http://www.boost.org/libs/range/
  10. //
  11. //[adjacent_filtered_example
  12. #include <boost/range/adaptor/adjacent_filtered.hpp>
  13. #include <boost/range/algorithm/copy.hpp>
  14. #include <boost/assign.hpp>
  15. #include <iterator>
  16. #include <functional>
  17. #include <iostream>
  18. #include <vector>
  19. //<-
  20. #include <boost/range/algorithm_ext/push_back.hpp>
  21. #include <boost/test/test_tools.hpp>
  22. #include <boost/test/unit_test.hpp>
  23. namespace
  24. {
  25. void adjacent_filtered_example_test()
  26. //->
  27. //=int main(int argc, const char* argv[])
  28. {
  29. using namespace boost::assign;
  30. using namespace boost::adaptors;
  31. std::vector<int> input;
  32. input += 1,1,2,2,2,3,4,5,6;
  33. boost::copy(
  34. input | adjacent_filtered(std::not_equal_to<int>()),
  35. std::ostream_iterator<int>(std::cout, ","));
  36. //= return 0;
  37. //=}
  38. //]
  39. std::vector<int> reference;
  40. reference += 1,2,3,4,5,6;
  41. std::vector<int> test;
  42. boost::push_back(test, input | adjacent_filtered(std::not_equal_to<int>()));
  43. BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
  44. test.begin(), test.end() );
  45. }
  46. }
  47. boost::unit_test::test_suite*
  48. init_unit_test_suite(int argc, char* argv[])
  49. {
  50. boost::unit_test::test_suite* test
  51. = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.adjacent_filtered_example" );
  52. test->add( BOOST_TEST_CASE( &adjacent_filtered_example_test ) );
  53. return test;
  54. }