]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/fusion/test/algorithm/for_each.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / fusion / test / algorithm / for_each.cpp
1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
3
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 ==============================================================================*/
7 #include <boost/detail/lightweight_test.hpp>
8 #include <boost/fusion/container/vector/vector.hpp>
9 #include <boost/fusion/adapted/mpl.hpp>
10 #include <boost/fusion/sequence/io/out.hpp>
11 #include <boost/fusion/algorithm/iteration/for_each.hpp>
12 #include <boost/mpl/vector_c.hpp>
13
14 struct print
15 {
16 template <typename T>
17 void operator()(T const& v) const
18 {
19 std::cout << "[ " << v << " ] ";
20 }
21 };
22
23 struct increment
24 {
25 template <typename T>
26 void operator()(T& v) const
27 {
28 ++v;
29 }
30 };
31
32 int
33 main()
34 {
35 using namespace boost::fusion;
36 using boost::mpl::vector_c;
37 namespace fusion = boost::fusion;
38
39 {
40 typedef vector<int, char, double, char const*> vector_type;
41 vector_type v(1, 'x', 3.3, "Ruby");
42 for_each(v, print());
43 std::cout << std::endl;
44 }
45
46 {
47 typedef vector<int, char, double, char const*> vector_type;
48 vector_type v(1, 'x', 3.3, "Ruby");
49 for_each(v, increment());
50 std::cout << v << std::endl;
51 }
52
53 {
54 typedef vector_c<int, 2, 3, 4, 5, 6> mpl_vec;
55 fusion::for_each(mpl_vec(), print());
56 std::cout << std::endl;
57 }
58
59 return boost::report_errors();
60 }
61