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 | ~static_visitor() = default; |
54 | #else |
55 | static_visitor() BOOST_NOEXCEPT { } |
56 | ~static_visitor() BOOST_NOEXCEPT { } |
57 | #endif |
58 | }; |
59 | |
60 | ////////////////////////////////////////////////////////////////////////// |
61 | // metafunction is_static_visitor |
62 | // |
63 | // Value metafunction indicates whether the specified type derives from |
64 | // static_visitor<...>. |
65 | // |
66 | // NOTE #1: This metafunction does NOT check whether the specified type |
67 | // fulfills the requirements of the StaticVisitor concept. |
68 | // |
69 | // NOTE #2: This template never needs to be specialized! |
70 | // |
71 | |
72 | namespace detail { |
73 | |
74 | template <typename T> |
75 | struct is_static_visitor_impl |
76 | { |
77 | BOOST_STATIC_CONSTANT(bool, value = |
78 | (::boost::is_base_and_derived< |
79 | detail::is_static_visitor_tag, |
80 | T |
81 | >::value)); |
82 | }; |
83 | |
84 | } // namespace detail |
85 | |
86 | template< typename T > struct is_static_visitor |
87 | : public ::boost::integral_constant<bool,(::boost::detail::is_static_visitor_impl<T>::value)> |
88 | { |
89 | public: |
90 | BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_static_visitor,(T)) |
91 | }; |
92 | |
93 | } // namespace boost |
94 | |
95 | #endif // BOOST_VARIANT_STATIC_VISITOR_HPP |
96 | |