cstr_byref.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 char *foreach_container_type;
  14. typedef char const *foreach_const_container_type;
  15. typedef char foreach_value_type;
  16. typedef char &foreach_reference_type;
  17. typedef char const &foreach_const_reference_type;
  18. #include "./utility.hpp"
  19. ///////////////////////////////////////////////////////////////////////////////
  20. // define some containers
  21. //
  22. char my_ntcs_buffer[] = "\1\2\3\4\5";
  23. char *my_ntcs = my_ntcs_buffer;
  24. char const *my_const_ntcs = my_ntcs;
  25. ///////////////////////////////////////////////////////////////////////////////
  26. // test_main
  27. //
  28. int test_main( int, char*[] )
  29. {
  30. // non-const containers by reference
  31. BOOST_CHECK(sequence_equal_byref_n(my_ntcs, "\1\2\3\4\5"));
  32. // const containers by reference
  33. BOOST_CHECK(sequence_equal_byref_c(my_const_ntcs, "\1\2\3\4\5"));
  34. // mutate the mutable collections
  35. mutate_foreach_byref(my_ntcs);
  36. // compare the mutated collections to the actual results
  37. BOOST_CHECK(sequence_equal_byref_n(my_ntcs, "\2\3\4\5\6"));
  38. return 0;
  39. }