1 | #include <boost/config.hpp> |
---|
2 | |
---|
3 | #if defined(BOOST_MSVC) |
---|
4 | # pragma warning(disable: 4786) // identifier truncated in debug info |
---|
5 | # pragma warning(disable: 4710) // function not inlined |
---|
6 | # pragma warning(disable: 4711) // function selected for automatic inline expansion |
---|
7 | # pragma warning(disable: 4514) // unreferenced inline removed |
---|
8 | #endif |
---|
9 | |
---|
10 | // Copyright (c) 2006 Douglas Gregor <doug.gregor@gmail.com> |
---|
11 | // Copyright (c) 2006 Peter Dimov |
---|
12 | // |
---|
13 | // Distributed under the Boost Software License, Version 1.0. (See |
---|
14 | // accompanying file LICENSE_1_0.txt or copy at |
---|
15 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
16 | |
---|
17 | #include <boost/bind.hpp> |
---|
18 | #include <boost/visit_each.hpp> |
---|
19 | |
---|
20 | #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) |
---|
21 | # pragma warning(push, 3) |
---|
22 | #endif |
---|
23 | |
---|
24 | #include <iostream> |
---|
25 | #include <typeinfo> |
---|
26 | |
---|
27 | #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) |
---|
28 | # pragma warning(pop) |
---|
29 | #endif |
---|
30 | |
---|
31 | #include <boost/detail/lightweight_test.hpp> |
---|
32 | |
---|
33 | struct visitor |
---|
34 | { |
---|
35 | int hash; |
---|
36 | |
---|
37 | visitor(): hash( 0 ) |
---|
38 | { |
---|
39 | } |
---|
40 | |
---|
41 | template<typename T> void operator()( T const & t ) |
---|
42 | { |
---|
43 | std::cout << "visitor::operator()( T ): " << typeid( t ).name() << std::endl; |
---|
44 | } |
---|
45 | |
---|
46 | void operator()( int const & t ) |
---|
47 | { |
---|
48 | std::cout << "visitor::operator()( int ): " << t << std::endl; |
---|
49 | hash = hash * 10 + t; |
---|
50 | } |
---|
51 | }; |
---|
52 | |
---|
53 | int f( int x, int y, int z ) |
---|
54 | { |
---|
55 | return x + y + z; |
---|
56 | } |
---|
57 | |
---|
58 | int main() |
---|
59 | { |
---|
60 | visitor vis; |
---|
61 | |
---|
62 | boost::visit_each( vis, boost::bind( f, 3, _1, 4 ) ); |
---|
63 | |
---|
64 | BOOST_TEST( vis.hash == 34 ); |
---|
65 | |
---|
66 | return boost::report_errors(); |
---|
67 | } |
---|