| 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 | # pragma warning(disable: 4100) // unreferenced formal parameter (it is referenced!) |
| 9 | #endif |
| 10 | |
| 11 | // Copyright (c) 2006 Douglas Gregor <doug.gregor@gmail.com> |
| 12 | // Copyright (c) 2006 Peter Dimov |
| 13 | // |
| 14 | // Distributed under the Boost Software License, Version 1.0. (See |
| 15 | // accompanying file LICENSE_1_0.txt or copy at |
| 16 | // http://www.boost.org/LICENSE_1_0.txt) |
| 17 | |
| 18 | #include <boost/bind/bind.hpp> |
| 19 | #include <boost/visit_each.hpp> |
| 20 | #include <boost/core/lightweight_test.hpp> |
| 21 | #include <typeinfo> |
| 22 | |
| 23 | using namespace boost::placeholders; |
| 24 | |
| 25 | // |
| 26 | |
| 27 | struct visitor |
| 28 | { |
| 29 | int hash; |
| 30 | |
| 31 | visitor(): hash( 0 ) |
| 32 | { |
| 33 | } |
| 34 | |
| 35 | template<typename T> void operator()( T const & t ) |
| 36 | { |
| 37 | std::cout << "visitor::operator()( T ): " << typeid( t ).name() << std::endl; |
| 38 | } |
| 39 | |
| 40 | void operator()( int const & t ) |
| 41 | { |
| 42 | std::cout << "visitor::operator()( int ): " << t << std::endl; |
| 43 | hash = hash * 10 + t; |
| 44 | } |
| 45 | }; |
| 46 | |
| 47 | int f( int x, int y, int z ) |
| 48 | { |
| 49 | return x + y + z; |
| 50 | } |
| 51 | |
| 52 | int main() |
| 53 | { |
| 54 | visitor vis; |
| 55 | |
| 56 | boost::visit_each( visitor&: vis, t: boost::bind( f, a1: 3, a2: _1, a3: 4 ) ); |
| 57 | |
| 58 | BOOST_TEST( vis.hash == 34 ); |
| 59 | |
| 60 | return boost::report_errors(); |
| 61 | } |
| 62 | |