bind_visit_test.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. Distributed under the Boost Software License, Version 1.0. (See accompanying
  7. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  8. ==============================================================================*/
  9. #include <boost/config.hpp>
  10. #if defined(BOOST_MSVC)
  11. # pragma warning(disable: 4786) // identifier truncated in debug info
  12. # pragma warning(disable: 4710) // function not inlined
  13. # pragma warning(disable: 4711) // function selected for automatic inline expansion
  14. # pragma warning(disable: 4514) // unreferenced inline removed
  15. # pragma warning(disable: 4100) // unreferenced formal parameter (it is referenced!)
  16. #endif
  17. #include <boost/phoenix/core.hpp>
  18. #include <boost/phoenix/bind.hpp>
  19. #include <boost/visit_each.hpp>
  20. #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
  21. # pragma warning(push, 3)
  22. #endif
  23. #include <iostream>
  24. #include <typeinfo>
  25. #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
  26. # pragma warning(pop)
  27. #endif
  28. #include <boost/detail/lightweight_test.hpp>
  29. struct visitor
  30. {
  31. int hash;
  32. visitor(): hash( 0 )
  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. void operator()( int const & t )
  40. {
  41. std::cout << "visitor::operator()( int ): " << t << std::endl;
  42. hash = hash * 10 + t;
  43. }
  44. };
  45. int f( int x, int y, int z )
  46. {
  47. return x + y + z;
  48. }
  49. int main()
  50. {
  51. using boost::phoenix::bind;
  52. using boost::phoenix::placeholders::_1;
  53. visitor vis;
  54. boost::visit_each( vis, bind( f, 3, _1, 4 ) );
  55. BOOST_TEST( vis.hash == 34 );
  56. return boost::report_errors();
  57. }