static_visitor.hpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. ~static_visitor() = default;
  41. #else
  42. static_visitor() BOOST_NOEXCEPT { }
  43. ~static_visitor() BOOST_NOEXCEPT { }
  44. #endif
  45. };
  46. //////////////////////////////////////////////////////////////////////////
  47. // metafunction is_static_visitor
  48. //
  49. // Value metafunction indicates whether the specified type derives from
  50. // static_visitor<...>.
  51. //
  52. // NOTE #1: This metafunction does NOT check whether the specified type
  53. // fulfills the requirements of the StaticVisitor concept.
  54. //
  55. // NOTE #2: This template never needs to be specialized!
  56. //
  57. namespace detail {
  58. template <typename T>
  59. struct is_static_visitor_impl
  60. {
  61. BOOST_STATIC_CONSTANT(bool, value =
  62. (::boost::is_base_and_derived<
  63. detail::is_static_visitor_tag,
  64. T
  65. >::value));
  66. };
  67. } // namespace detail
  68. template< typename T > struct is_static_visitor
  69. : public ::boost::integral_constant<bool,(::boost::detail::is_static_visitor_impl<T>::value)>
  70. {
  71. public:
  72. BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_static_visitor,(T))
  73. };
  74. } // namespace boost
  75. #endif // BOOST_VARIANT_STATIC_VISITOR_HPP