apply_visitor_unary.hpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //-----------------------------------------------------------------------------
  2. // boost variant/detail/apply_visitor_unary.hpp header file
  3. // See http://www.boost.org for updates, documentation, and revision history.
  4. //-----------------------------------------------------------------------------
  5. //
  6. // Copyright (c) 2002-2003
  7. // Eric Friedman
  8. //
  9. // Distributed under the Boost Software License, Version 1.0. (See
  10. // accompanying file LICENSE_1_0.txt or copy at
  11. // http://www.boost.org/LICENSE_1_0.txt)
  12. #ifndef BOOST_VARIANT_DETAIL_APPLY_VISITOR_UNARY_HPP
  13. #define BOOST_VARIANT_DETAIL_APPLY_VISITOR_UNARY_HPP
  14. #include "boost/config.hpp"
  15. #include "boost/detail/workaround.hpp"
  16. #include "boost/variant/detail/generic_result_type.hpp"
  17. #if BOOST_WORKAROUND(__EDG__, BOOST_TESTED_AT(302))
  18. #include "boost/utility/enable_if.hpp"
  19. #include "boost/mpl/not.hpp"
  20. #include "boost/type_traits/is_const.hpp"
  21. #endif
  22. namespace boost {
  23. //////////////////////////////////////////////////////////////////////////
  24. // function template apply_visitor(visitor, visitable)
  25. //
  26. // Visits visitable with visitor.
  27. //
  28. //
  29. // nonconst-visitor version:
  30. //
  31. #if !BOOST_WORKAROUND(__EDG__, BOOST_TESTED_AT(302))
  32. # define BOOST_VARIANT_AUX_APPLY_VISITOR_NON_CONST_RESULT_TYPE(V) \
  33. BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(typename V::result_type) \
  34. /**/
  35. #else // EDG-based compilers
  36. # define BOOST_VARIANT_AUX_APPLY_VISITOR_NON_CONST_RESULT_TYPE(V) \
  37. typename enable_if< \
  38. mpl::not_< is_const< V > > \
  39. , BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(typename V::result_type) \
  40. >::type \
  41. /**/
  42. #endif // EDG-based compilers workaround
  43. template <typename Visitor, typename Visitable>
  44. inline
  45. BOOST_VARIANT_AUX_APPLY_VISITOR_NON_CONST_RESULT_TYPE(Visitor)
  46. apply_visitor(Visitor& visitor, Visitable& visitable)
  47. {
  48. return visitable.apply_visitor(visitor);
  49. }
  50. #undef BOOST_VARIANT_AUX_APPLY_VISITOR_NON_CONST_RESULT_TYPE
  51. //
  52. // const-visitor version:
  53. //
  54. #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
  55. template <typename Visitor, typename Visitable>
  56. inline
  57. BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(typename Visitor::result_type)
  58. apply_visitor(const Visitor& visitor, Visitable& visitable)
  59. {
  60. return visitable.apply_visitor(visitor);
  61. }
  62. #endif // MSVC7 and below exclusion
  63. } // namespace boost
  64. #endif // BOOST_VARIANT_DETAIL_APPLY_VISITOR_UNARY_HPP