| 1 | // stl_byval.cpp |
|---|
| 2 | /// |
|---|
| 3 | // (C) Copyright Eric Niebler 2004. |
|---|
| 4 | // Use, modification and distribution are subject to the |
|---|
| 5 | // Boost Software License, Version 1.0. (See accompanying file |
|---|
| 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 7 | |
|---|
| 8 | /* |
|---|
| 9 | Revision history: |
|---|
| 10 | 25 August 2005 : Initial version. |
|---|
| 11 | */ |
|---|
| 12 | |
|---|
| 13 | #include <list> |
|---|
| 14 | #include <boost/test/minimal.hpp> |
|---|
| 15 | #include <boost/foreach.hpp> |
|---|
| 16 | |
|---|
| 17 | /////////////////////////////////////////////////////////////////////////////// |
|---|
| 18 | // define the container types, used by utility.hpp to generate the helper functions |
|---|
| 19 | typedef std::list<int> foreach_container_type; |
|---|
| 20 | typedef std::list<int> const foreach_const_container_type; |
|---|
| 21 | typedef int foreach_value_type; |
|---|
| 22 | typedef int &foreach_reference_type; |
|---|
| 23 | typedef int const &foreach_const_reference_type; |
|---|
| 24 | |
|---|
| 25 | #include "./utility.hpp" |
|---|
| 26 | |
|---|
| 27 | /////////////////////////////////////////////////////////////////////////////// |
|---|
| 28 | // initialize a std::list<int> |
|---|
| 29 | std::list<int> make_list() |
|---|
| 30 | { |
|---|
| 31 | std::list<int> l; |
|---|
| 32 | l.push_back(1); |
|---|
| 33 | l.push_back(2); |
|---|
| 34 | l.push_back(3); |
|---|
| 35 | l.push_back(4); |
|---|
| 36 | l.push_back(5); |
|---|
| 37 | return l; |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | /////////////////////////////////////////////////////////////////////////////// |
|---|
| 41 | // define come containers |
|---|
| 42 | // |
|---|
| 43 | std::list<int> my_list = make_list(); |
|---|
| 44 | std::list<int> const &my_const_list = my_list; |
|---|
| 45 | |
|---|
| 46 | /////////////////////////////////////////////////////////////////////////////// |
|---|
| 47 | // test_main |
|---|
| 48 | // |
|---|
| 49 | int test_main( int, char*[] ) |
|---|
| 50 | { |
|---|
| 51 | boost::mpl::false_ *p = BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(my_list); |
|---|
| 52 | |
|---|
| 53 | // non-const containers by value |
|---|
| 54 | BOOST_CHECK(sequence_equal_byval_n(my_list, "\1\2\3\4\5")); |
|---|
| 55 | |
|---|
| 56 | // const containers by value |
|---|
| 57 | BOOST_CHECK(sequence_equal_byval_c(my_const_list, "\1\2\3\4\5")); |
|---|
| 58 | |
|---|
| 59 | return 0; |
|---|
| 60 | } |
|---|