pair_byref_r.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. 13 December 2004 : Initial version.
  8. 25 August 2005 : Initial version.
  9. */
  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::pair<int*,int*> foreach_container_type;
  15. typedef std::pair<int const*,int const*> 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. // define some containers
  22. //
  23. int my_array[] = { 1,2,3,4,5 };
  24. std::pair<int*,int*> my_pair(my_array,my_array+5);
  25. std::pair<int const*,int const*> const my_const_pair(my_array,my_array+5);
  26. ///////////////////////////////////////////////////////////////////////////////
  27. // test_main
  28. //
  29. int test_main( int, char*[] )
  30. {
  31. // non-const containers by reference
  32. BOOST_CHECK(sequence_equal_byref_n_r(my_pair, "\5\4\3\2\1"));
  33. // const containers by reference
  34. BOOST_CHECK(sequence_equal_byref_c_r(my_const_pair, "\5\4\3\2\1"));
  35. // mutate the mutable collections
  36. mutate_foreach_byref_r(my_pair);
  37. // compare the mutated collections to the actual results
  38. BOOST_CHECK(sequence_equal_byref_n_r(my_pair, "\6\5\4\3\2"));
  39. return 0;
  40. }