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