array_byref_r.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 <boost/test/minimal.hpp>
  10. #include <boost/foreach.hpp>
  11. ///////////////////////////////////////////////////////////////////////////////
  12. // define the container types, used by utility.hpp to generate the helper functions
  13. typedef int foreach_container_type[5];
  14. typedef int const foreach_const_container_type[5];
  15. typedef int foreach_value_type;
  16. typedef int &foreach_reference_type;
  17. typedef int const &foreach_const_reference_type;
  18. #include "./utility.hpp"
  19. ///////////////////////////////////////////////////////////////////////////////
  20. // define some containers
  21. //
  22. int my_array[5] = { 1,2,3,4,5 };
  23. int const (&my_const_array)[5] = my_array;
  24. ///////////////////////////////////////////////////////////////////////////////
  25. // test_main
  26. //
  27. int test_main( int, char*[] )
  28. {
  29. // non-const containers by reference
  30. BOOST_CHECK(sequence_equal_byref_n_r(my_array, "\5\4\3\2\1"));
  31. // const containers by reference
  32. BOOST_CHECK(sequence_equal_byref_c_r(my_const_array, "\5\4\3\2\1"));
  33. // mutate the mutable collections
  34. mutate_foreach_byref_r(my_array);
  35. // compare the mutated collections to the actual results
  36. BOOST_CHECK(sequence_equal_byref_n_r(my_array, "\6\5\4\3\2"));
  37. return 0;
  38. }