1 //-----------------------------------------------------------------------------
2 // boost variant/detail/apply_visitor_delayed.hpp header file
3 // See http://www.boost.org for updates, documentation, and revision history.
4 //-----------------------------------------------------------------------------
6 // Copyright (c) 2002-2003
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)
13 #ifndef BOOST_VARIANT_DETAIL_APPLY_VISITOR_DELAYED_HPP
14 #define BOOST_VARIANT_DETAIL_APPLY_VISITOR_DELAYED_HPP
16 #include <boost/variant/detail/apply_visitor_unary.hpp>
17 #include <boost/variant/detail/apply_visitor_binary.hpp>
18 #include <boost/variant/variant_fwd.hpp> // for BOOST_VARIANT_DO_NOT_USE_VARIADIC_TEMPLATES
21 #include <boost/variant/detail/has_result_type.hpp>
22 #include <boost/core/enable_if.hpp>
26 //////////////////////////////////////////////////////////////////////////
27 // function template apply_visitor(visitor)
29 // Returns a function object, overloaded for unary and binary usage, that
30 // visits its arguments using visitor (or a copy of visitor) via
31 // * apply_visitor( visitor, [argument] )
32 // under unary invocation, or
33 // * apply_visitor( visitor, [argument1], [argument2] )
34 // under binary invocation.
36 // NOTE: Unlike other apply_visitor forms, the visitor object must be
37 // non-const; this prevents user from giving temporary, to disastrous
38 // effect (i.e., returned function object would have dead reference).
41 template <typename Visitor>
42 class apply_visitor_delayed_t
44 public: // visitor typedefs
46 typedef typename Visitor::result_type
49 private: // representation
55 explicit apply_visitor_delayed_t(Visitor& visitor) BOOST_NOEXCEPT
60 #if !defined(BOOST_VARIANT_DO_NOT_USE_VARIADIC_TEMPLATES)
62 public: // N-ary visitor interface
63 template <typename... Visitables>
64 result_type operator()(Visitables&... visitables) const
66 return apply_visitor(visitor_, visitables...);
69 #else // !defined(BOOST_VARIANT_DO_NOT_USE_VARIADIC_TEMPLATES)
71 public: // unary visitor interface
73 template <typename Visitable>
74 result_type operator()(Visitable& visitable) const
76 return apply_visitor(visitor_, visitable);
79 public: // binary visitor interface
81 template <typename Visitable1, typename Visitable2>
82 result_type operator()(Visitable1& visitable1, Visitable2& visitable2) const
84 return apply_visitor(visitor_, visitable1, visitable2);
87 #endif // !defined(BOOST_VARIANT_DO_NOT_USE_VARIADIC_TEMPLATES)
90 apply_visitor_delayed_t& operator=(const apply_visitor_delayed_t&);
94 template <typename Visitor>
95 inline typename boost::enable_if<
96 boost::detail::variant::has_result_type<Visitor>,
97 apply_visitor_delayed_t<Visitor>
98 >::type apply_visitor(Visitor& visitor)
100 return apply_visitor_delayed_t<Visitor>(visitor);
103 #if !defined(BOOST_NO_CXX14_DECLTYPE_AUTO) && !defined(BOOST_NO_CXX11_DECLTYPE_N3276) \
104 && !defined(BOOST_VARIANT_DO_NOT_USE_VARIADIC_TEMPLATES)
106 template <typename Visitor>
107 class apply_visitor_delayed_cpp14_t
109 private: // representation
114 explicit apply_visitor_delayed_cpp14_t(Visitor& visitor) BOOST_NOEXCEPT
119 public: // N-ary visitor interface
120 template <typename... Visitables>
121 decltype(auto) operator()(Visitables&... visitables) const
123 return apply_visitor(visitor_, visitables...);
127 apply_visitor_delayed_cpp14_t& operator=(const apply_visitor_delayed_cpp14_t&);
131 template <typename Visitor>
132 inline typename boost::disable_if<
133 boost::detail::variant::has_result_type<Visitor>,
134 apply_visitor_delayed_cpp14_t<Visitor>
135 >::type apply_visitor(Visitor& visitor)
137 return apply_visitor_delayed_cpp14_t<Visitor>(visitor);
140 #endif // !defined(BOOST_NO_CXX14_DECLTYPE_AUTO) && !defined(BOOST_NO_CXX11_DECLTYPE_N3276)
141 // && !defined(BOOST_VARIANT_DO_NOT_USE_VARIADIC_TEMPLATES)
146 #endif // BOOST_VARIANT_DETAIL_APPLY_VISITOR_DELAYED_HPP