Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:33

0001 //-----------------------------------------------------------------------------
0002 // boost variant/visitor_ptr.hpp header file
0003 // See http://www.boost.org for updates, documentation, and revision history.
0004 //-----------------------------------------------------------------------------
0005 //
0006 // Copyright (c) 2002-2003
0007 // Eric Friedman
0008 //
0009 // Distributed under the Boost Software License, Version 1.0. (See
0010 // accompanying file LICENSE_1_0.txt or copy at
0011 // http://www.boost.org/LICENSE_1_0.txt)
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 // function template visitor_ptr
0030 //
0031 // Adapts a function pointer for use as visitor capable of handling
0032 // values of a single type. Throws bad_visit if inappropriately applied.
0033 //
0034 template <typename T, typename R>
0035 class visitor_ptr_t
0036     : public static_visitor<R>
0037 {
0038 private: // representation
0039 
0040     typedef R (*visitor_t)(T);
0041 
0042     visitor_t visitor_;
0043 
0044 public: // typedefs
0045 
0046     typedef R result_type;
0047 
0048 private: // private typedefs
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: // structors
0057 
0058     explicit visitor_ptr_t(visitor_t visitor) BOOST_NOEXCEPT
0059       : visitor_(visitor)
0060     {
0061     }
0062 
0063 public: // static visitor interfaces
0064 
0065     template <typename U>
0066     result_type operator()(const U&) const
0067     {
0068         boost::throw_exception(bad_visit());
0069     }
0070 
0071 public: // static visitor interfaces, cont.
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 } // namespace boost
0087 
0088 #endif// BOOST_VISITOR_VISITOR_PTR_HPP