static_visitor.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //-----------------------------------------------------------------------------
  2. // boost variant/static_visitor.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_STATIC_VISITOR_HPP
  13. #define BOOST_VARIANT_STATIC_VISITOR_HPP
  14. #include <boost/config.hpp>
  15. #include <boost/detail/workaround.hpp>
  16. #include <boost/mpl/if.hpp>
  17. #include <boost/type_traits/is_base_and_derived.hpp>
  18. #include <boost/type_traits/integral_constant.hpp>
  19. #include <boost/mpl/aux_/lambda_support.hpp>
  20. namespace boost {
  21. //////////////////////////////////////////////////////////////////////////
  22. // class template static_visitor
  23. //
  24. // An empty base class that typedefs the return type of a deriving static
  25. // visitor. The class is analogous to std::unary_function in this role.
  26. //
  27. namespace detail {
  28. struct is_static_visitor_tag { };
  29. typedef void static_visitor_default_return;
  30. } // namespace detail
  31. template <typename R = ::boost::detail::static_visitor_default_return>
  32. class static_visitor
  33. : public detail::is_static_visitor_tag
  34. {
  35. public: // typedefs
  36. typedef R result_type;
  37. protected: // for use as base class only
  38. #if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) && !defined(BOOST_NO_CXX11_NON_PUBLIC_DEFAULTED_FUNCTIONS)
  39. static_visitor() = default;
  40. #else
  41. static_visitor() BOOST_NOEXCEPT { }
  42. #endif
  43. };
  44. //////////////////////////////////////////////////////////////////////////
  45. // metafunction is_static_visitor
  46. //
  47. // Value metafunction indicates whether the specified type derives from
  48. // static_visitor<...>.
  49. //
  50. // NOTE #1: This metafunction does NOT check whether the specified type
  51. // fulfills the requirements of the StaticVisitor concept.
  52. //
  53. // NOTE #2: This template never needs to be specialized!
  54. //
  55. namespace detail {
  56. template <typename T>
  57. struct is_static_visitor_impl
  58. {
  59. BOOST_STATIC_CONSTANT(bool, value =
  60. (::boost::is_base_and_derived<
  61. detail::is_static_visitor_tag,
  62. T
  63. >::value));
  64. };
  65. } // namespace detail
  66. template< typename T > struct is_static_visitor
  67. : public ::boost::integral_constant<bool,(::boost::detail::is_static_visitor_impl<T>::value)>
  68. {
  69. public:
  70. BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_static_visitor,(T))
  71. };
  72. } // namespace boost
  73. #endif // BOOST_VARIANT_STATIC_VISITOR_HPP