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