stl_byref_r.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // (C) Copyright Eric Niebler 2004.
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. /*
  6. Revision history:
  7. 25 August 2005: Initial version.
  8. */
  9. #include <list>
  10. #include <boost/test/minimal.hpp>
  11. #include <boost/foreach.hpp>
  12. ///////////////////////////////////////////////////////////////////////////////
  13. // define the container types, used by utility.hpp to generate the helper functions
  14. typedef std::list<int> foreach_container_type;
  15. typedef std::list<int> const foreach_const_container_type;
  16. typedef int foreach_value_type;
  17. typedef int &foreach_reference_type;
  18. typedef int const &foreach_const_reference_type;
  19. #include "./utility.hpp"
  20. ///////////////////////////////////////////////////////////////////////////////
  21. // initialize a std::list<int>
  22. std::list<int> make_list()
  23. {
  24. std::list<int> l;
  25. l.push_back(1);
  26. l.push_back(2);
  27. l.push_back(3);
  28. l.push_back(4);
  29. l.push_back(5);
  30. return l;
  31. }
  32. ///////////////////////////////////////////////////////////////////////////////
  33. // define some containers
  34. //
  35. std::list<int> my_list = make_list();
  36. std::list<int> const &my_const_list = my_list;
  37. ///////////////////////////////////////////////////////////////////////////////
  38. // test_main
  39. //
  40. int test_main( int, char*[] )
  41. {
  42. // non-const containers by reference
  43. BOOST_CHECK(sequence_equal_byref_n_r(my_list, "\5\4\3\2\1"));
  44. // const containers by reference
  45. BOOST_CHECK(sequence_equal_byref_c_r(my_const_list, "\5\4\3\2\1"));
  46. // mutate the mutable collections
  47. mutate_foreach_byref_r(my_list);
  48. // compare the mutated collections to the actual results
  49. BOOST_CHECK(sequence_equal_byref_n_r(my_list, "\6\5\4\3\2"));
  50. return 0;
  51. }