File indexing completed on 2025-01-18 09:53:33
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef BOOST_VARIANT_VISITOR_PTR_HPP
0014 #define BOOST_VARIANT_VISITOR_PTR_HPP
0015
0016 #include <boost/variant/bad_visit.hpp>
0017 #include <boost/variant/static_visitor.hpp>
0018
0019 #include <boost/mpl/eval_if.hpp>
0020 #include <boost/mpl/identity.hpp>
0021 #include <boost/throw_exception.hpp>
0022 #include <boost/type_traits/add_reference.hpp>
0023 #include <boost/type_traits/is_reference.hpp>
0024 #include <boost/type_traits/is_void.hpp>
0025
0026 namespace boost {
0027
0028
0029
0030
0031
0032
0033
0034 template <typename T, typename R>
0035 class visitor_ptr_t
0036 : public static_visitor<R>
0037 {
0038 private:
0039
0040 typedef R (*visitor_t)(T);
0041
0042 visitor_t visitor_;
0043
0044 public:
0045
0046 typedef R result_type;
0047
0048 private:
0049
0050 typedef typename mpl::eval_if<
0051 is_reference<T>
0052 , mpl::identity<T>
0053 , add_reference<const T>
0054 >::type argument_fwd_type;
0055
0056 public:
0057
0058 explicit visitor_ptr_t(visitor_t visitor) BOOST_NOEXCEPT
0059 : visitor_(visitor)
0060 {
0061 }
0062
0063 public:
0064
0065 template <typename U>
0066 result_type operator()(const U&) const
0067 {
0068 boost::throw_exception(bad_visit());
0069 }
0070
0071 public:
0072
0073 result_type operator()(argument_fwd_type operand) const
0074 {
0075 return visitor_(operand);
0076 }
0077
0078 };
0079
0080 template <typename R, typename T>
0081 inline visitor_ptr_t<T,R> visitor_ptr(R (*visitor)(T))
0082 {
0083 return visitor_ptr_t<T,R>(visitor);
0084 }
0085
0086 }
0087
0088 #endif