ticket_8676_sliced_transformed.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Boost.Range library
  2. //
  3. // Copyright Neil Groves 2014. 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. #include <boost/range/adaptor/sliced.hpp>
  12. #include <boost/range/adaptor/transformed.hpp>
  13. #include <boost/range/algorithm_ext/push_back.hpp>
  14. #include <boost/test/test_tools.hpp>
  15. #include <boost/test/unit_test.hpp>
  16. #include <vector>
  17. namespace
  18. {
  19. struct identity
  20. {
  21. typedef int result_type;
  22. result_type operator()(int i) const { return i; }
  23. };
  24. void sliced_and_transformed()
  25. {
  26. using namespace boost::adaptors;
  27. std::vector<int> input;
  28. for (int i = 0; i < 10; ++i)
  29. input.push_back(i);
  30. std::vector<int> out1;
  31. boost::push_back(out1, input | sliced(2, 8)
  32. | transformed(identity()));
  33. std::vector<int> out2;
  34. boost::push_back(out2, input | transformed(identity())
  35. | sliced(2, 8));
  36. BOOST_CHECK_EQUAL_COLLECTIONS(out1.begin(), out1.end(),
  37. out2.begin(), out2.end());
  38. }
  39. } // anonymous namespace
  40. boost::unit_test::test_suite*
  41. init_unit_test_suite(int argc, char* argv[])
  42. {
  43. boost::unit_test::test_suite* test
  44. = BOOST_TEST_SUITE( "Range adaptors - sliced and transformed" );
  45. test->add(BOOST_TEST_CASE(&sliced_and_transformed));
  46. return test;
  47. }