]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/test/test/utils-ts/foreach-test.cpp
1 // (C) Copyright Gennadiy Rozental 2001-2015.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 // See http://www.boost.org/libs/test for the library home page.
10 // Version : $Revision$
12 // Description : BOOST_TEST_FOREACH compile only test
13 // *****************************************************************************
21 #include <boost/test/utils/foreach.hpp>
24 #pragma warning(disable:4702) // Unreachable code
28 void baz( std::list
<T
>const& list_of_T
)
30 // an example of using BOOST_TEST_FOREACH with dependent types
31 BOOST_TEST_FOREACH( T
const&, t
, list_of_T
)
33 std::cout
<< t
<< std::endl
;
39 std::list
<int> int_list
;
40 int_list
.push_back( 1 );
41 int_list
.push_back( 2 );
42 int_list
.push_back( 3 );
44 // use BOOST_TEST_FOREACH with a STL container, and a reference as the loop variable.
45 BOOST_TEST_FOREACH( int&, i
, int_list
)
48 std::cout
<< i
<< std::endl
;
51 std::cout
<< std::endl
;
53 // use BOOST_TEST_FOREACH with a std::vector
54 std::vector
<int> int_vec
;
55 int_vec
.push_back( 1 );
56 int_vec
.push_back( 2 );
57 int_vec
.push_back( 3 );
58 int_vec
.push_back( 3 );
59 int_vec
.push_back( 3 );
61 BOOST_TEST_FOREACH( int const&, i
, int_vec
)
63 std::cout
<< i
<< std::endl
;
68 std::cout
<< std::endl
;
70 // use BOOST_TEST_FOREACH with dependent types
72 std::cout
<< std::endl
;
74 // iterate over characters in a std::string
75 std::string
str( "hello" );
77 BOOST_TEST_FOREACH( char&, ch
, str
)
83 std::cout
<< std::endl
;
84 std::cout
<< std::endl
;
86 BOOST_TEST_FOREACH( char, ch
, str
)
88 // break work as you would expect
92 std::cout
<< std::endl
;
93 std::cout
<< std::endl
;
95 BOOST_TEST_FOREACH( char, ch
, str
)
97 // continue work as you would expect
103 std::cout
<< std::endl
;
104 std::cout
<< std::endl
;
106 // use BOOST_TEST_FOREACH with const reference.
107 std::vector
<int> const& int_vec_const_ref
= int_vec
;
109 BOOST_TEST_FOREACH( int const&, i
, int_vec_const_ref
)
111 std::cout
<< (i
+1) << std::endl
;
113 std::cout
<< std::endl
;