indirected_example.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. //[indirected_example
  12. #include <boost/range/adaptor/indirected.hpp>
  13. #include <boost/range/algorithm/copy.hpp>
  14. #include <boost/shared_ptr.hpp>
  15. #include <iterator>
  16. #include <iostream>
  17. #include <vector>
  18. //<-
  19. #include <boost/test/test_tools.hpp>
  20. #include <boost/test/unit_test.hpp>
  21. #include <boost/range/algorithm_ext/push_back.hpp>
  22. namespace
  23. {
  24. void indirected_example_test()
  25. //->
  26. //=int main(int argc, const char* argv[])
  27. {
  28. using namespace boost::adaptors;
  29. std::vector<boost::shared_ptr<int> > input;
  30. for (int i = 0; i < 10; ++i)
  31. input.push_back(boost::shared_ptr<int>(new int(i)));
  32. boost::copy(
  33. input | indirected,
  34. std::ostream_iterator<int>(std::cout, ","));
  35. //= return 0;
  36. //=}
  37. //]
  38. std::vector<int> reference;
  39. for (int i = 0; i < 10; ++i)
  40. reference.push_back(i);
  41. std::vector<int> test;
  42. boost::push_back(test, input | indirected);
  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.indirected_example" );
  52. test->add( BOOST_TEST_CASE( &indirected_example_test ) );
  53. return test;
  54. }