• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /*
7  Revision history:
8    25 August 2005: Initial version.
9 */
10 
11 #include <list>
12 #include <boost/test/minimal.hpp>
13 #include <boost/foreach.hpp>
14 
15 ///////////////////////////////////////////////////////////////////////////////
16 // define the container types, used by utility.hpp to generate the helper functions
17 typedef std::list<int> foreach_container_type;
18 typedef std::list<int> const foreach_const_container_type;
19 typedef int foreach_value_type;
20 typedef int &foreach_reference_type;
21 typedef int const &foreach_const_reference_type;
22 
23 #include "./utility.hpp"
24 
25 ///////////////////////////////////////////////////////////////////////////////
26 // initialize a std::list<int>
make_list()27 std::list<int> make_list()
28 {
29     std::list<int> l;
30     l.push_back(1);
31     l.push_back(2);
32     l.push_back(3);
33     l.push_back(4);
34     l.push_back(5);
35     return l;
36 }
37 
38 ///////////////////////////////////////////////////////////////////////////////
39 // define some containers
40 //
41 std::list<int> my_list = make_list();
42 std::list<int> const &my_const_list = my_list;
43 
44 ///////////////////////////////////////////////////////////////////////////////
45 // test_main
46 //
test_main(int,char * [])47 int test_main( int, char*[] )
48 {
49     // non-const containers by reference
50     BOOST_CHECK(sequence_equal_byref_n(my_list, "\1\2\3\4\5"));
51 
52     // const containers by reference
53     BOOST_CHECK(sequence_equal_byref_c(my_const_list, "\1\2\3\4\5"));
54 
55     // mutate the mutable collections
56     mutate_foreach_byref(my_list);
57 
58     // compare the mutated collections to the actual results
59     BOOST_CHECK(sequence_equal_byref_n(my_list, "\2\3\4\5\6"));
60 
61     return 0;
62 }
63