1 //-----------------------------------------------------------------------------
2 // boost variant/visitor_ptr.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_VISITOR_PTR_HPP
14 #define BOOST_VARIANT_VISITOR_PTR_HPP
16 #include <boost/variant/bad_visit.hpp>
17 #include <boost/variant/static_visitor.hpp>
19 #include <boost/mpl/eval_if.hpp>
20 #include <boost/mpl/identity.hpp>
21 #include <boost/throw_exception.hpp>
22 #include <boost/type_traits/add_reference.hpp>
23 #include <boost/type_traits/is_reference.hpp>
24 #include <boost/type_traits/is_void.hpp>
28 //////////////////////////////////////////////////////////////////////////
29 // function template visitor_ptr
31 // Adapts a function pointer for use as visitor capable of handling
32 // values of a single type. Throws bad_visit if inappropriately applied.
34 template <typename T, typename R>
36 : public static_visitor<R>
38 private: // representation
40 typedef R (*visitor_t)(T);
46 typedef R result_type;
48 private: // private typedefs
50 typedef typename mpl::eval_if<
53 , add_reference<const T>
54 >::type argument_fwd_type;
58 explicit visitor_ptr_t(visitor_t visitor) BOOST_NOEXCEPT
63 public: // static visitor interfaces
66 result_type operator()(const U&) const
68 boost::throw_exception(bad_visit());
71 public: // static visitor interfaces, cont.
73 result_type operator()(argument_fwd_type operand) const
75 return visitor_(operand);
80 template <typename R, typename T>
81 inline visitor_ptr_t<T,R> visitor_ptr(R (*visitor)(T))
83 return visitor_ptr_t<T,R>(visitor);
88 #endif// BOOST_VISITOR_VISITOR_PTR_HPP