stl_byval_r.cpp 1.7 KB

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