Brian Silverman | ce4aa8d | 2018-08-04 23:36:03 -0700 | [diff] [blame^] | 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 | // |
| 11 | // bind_visitor.cpp - tests bind.hpp with a visitor |
| 12 | // |
| 13 | // Copyright (c) 2001 Peter Dimov and Multi Media Ltd. |
| 14 | // |
| 15 | // Distributed under the Boost Software License, Version 1.0. (See |
| 16 | // accompanying file LICENSE_1_0.txt or copy at |
| 17 | // http://www.boost.org/LICENSE_1_0.txt) |
| 18 | // |
| 19 | |
| 20 | #include <boost/bind.hpp> |
| 21 | #include <boost/ref.hpp> |
| 22 | |
| 23 | #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) |
| 24 | #pragma warning(push, 3) |
| 25 | #endif |
| 26 | |
| 27 | #include <iostream> |
| 28 | #include <typeinfo> |
| 29 | |
| 30 | #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) |
| 31 | #pragma warning(pop) |
| 32 | #endif |
| 33 | |
| 34 | // |
| 35 | |
| 36 | struct visitor |
| 37 | { |
| 38 | template<class T> void operator()( boost::reference_wrapper<T> const & r ) const |
| 39 | { |
| 40 | std::cout << "Reference to " << typeid(T).name() << " @ " << &r.get() << " (with value " << r.get() << ")\n"; |
| 41 | } |
| 42 | |
| 43 | template<class T> void operator()( T const & t ) const |
| 44 | { |
| 45 | std::cout << "Value of type " << typeid(T).name() << " (with value " << t << ")\n"; |
| 46 | } |
| 47 | }; |
| 48 | |
| 49 | int f(int & i, int & j, int) |
| 50 | { |
| 51 | ++i; |
| 52 | --j; |
| 53 | return i + j; |
| 54 | } |
| 55 | |
| 56 | int x = 2; |
| 57 | int y = 7; |
| 58 | |
| 59 | int main() |
| 60 | { |
| 61 | using namespace boost; |
| 62 | |
| 63 | visitor v; |
| 64 | visit_each(v, bind<int>(bind(f, ref(x), _1, 42), ref(y)), 0); |
| 65 | } |