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/core/lightweight_test.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> |
27 | std::list<int> make_list() |
28 | { |
29 | std::list<int> l; |
30 | l.push_back(x: 1); |
31 | l.push_back(x: 2); |
32 | l.push_back(x: 3); |
33 | l.push_back(x: 4); |
34 | l.push_back(x: 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 | // |
47 | int main() |
48 | { |
49 | // non-const containers by reference |
50 | BOOST_TEST(sequence_equal_byref_n(my_list, "\1\2\3\4\5" )); |
51 | |
52 | // const containers by reference |
53 | BOOST_TEST(sequence_equal_byref_c(my_const_list, "\1\2\3\4\5" )); |
54 | |
55 | // mutate the mutable collections |
56 | mutate_foreach_byref(rng&: my_list); |
57 | |
58 | // compare the mutated collections to the actual results |
59 | BOOST_TEST(sequence_equal_byref_n(my_list, "\2\3\4\5\6" )); |
60 | |
61 | return boost::report_errors(); |
62 | } |
63 | |