epoc32/include/stdapis/boost/variant/visitor_ptr.hpp
branchSymbian2
changeset 2 2fe1408b6811
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/stdapis/boost/variant/visitor_ptr.hpp	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,116 @@
     1.4 +//-----------------------------------------------------------------------------
     1.5 +// boost variant/visitor_ptr.hpp header file
     1.6 +// See http://www.boost.org for updates, documentation, and revision history.
     1.7 +//-----------------------------------------------------------------------------
     1.8 +//
     1.9 +// Copyright (c) 2002-2003
    1.10 +// Eric Friedman
    1.11 +//
    1.12 +// Distributed under the Boost Software License, Version 1.0. (See
    1.13 +// accompanying file LICENSE_1_0.txt or copy at
    1.14 +// http://www.boost.org/LICENSE_1_0.txt)
    1.15 +
    1.16 +#ifndef BOOST_VARIANT_VISITOR_PTR_HPP
    1.17 +#define BOOST_VARIANT_VISITOR_PTR_HPP
    1.18 +
    1.19 +#include "boost/variant/bad_visit.hpp"
    1.20 +#include "boost/variant/static_visitor.hpp"
    1.21 +
    1.22 +#include "boost/mpl/eval_if.hpp"
    1.23 +#include "boost/mpl/identity.hpp"
    1.24 +#include "boost/type_traits/add_reference.hpp"
    1.25 +#include "boost/type_traits/is_reference.hpp"
    1.26 +#include "boost/type_traits/is_void.hpp"
    1.27 +
    1.28 +namespace boost {
    1.29 +
    1.30 +//////////////////////////////////////////////////////////////////////////
    1.31 +// function template visitor_ptr
    1.32 +//
    1.33 +// Adapts a function pointer for use as visitor capable of handling
    1.34 +// values of a single type. Throws bad_visit if inappropriately applied.
    1.35 +//
    1.36 +template <typename T, typename R>
    1.37 +class visitor_ptr_t
    1.38 +    : public static_visitor<R>
    1.39 +{
    1.40 +private: // representation
    1.41 +
    1.42 +    typedef R (*visitor_t)(T);
    1.43 +
    1.44 +    visitor_t visitor_;
    1.45 +
    1.46 +public: // typedefs
    1.47 +
    1.48 +    typedef R result_type;
    1.49 +
    1.50 +private: // private typedefs
    1.51 +
    1.52 +    typedef typename mpl::eval_if<
    1.53 +          is_reference<T>
    1.54 +        , mpl::identity<T>
    1.55 +        , add_reference<const T>
    1.56 +        >::type argument_fwd_type;
    1.57 +
    1.58 +public: // structors
    1.59 +
    1.60 +    explicit visitor_ptr_t(visitor_t visitor)
    1.61 +      : visitor_(visitor)
    1.62 +    {
    1.63 +    }
    1.64 +
    1.65 +public: // static visitor interfaces
    1.66 +
    1.67 +    template <typename U>
    1.68 +    result_type operator()(const U&) const
    1.69 +    {
    1.70 +        throw bad_visit();
    1.71 +    }
    1.72 +
    1.73 +#if !defined(BOOST_NO_VOID_RETURNS)
    1.74 +
    1.75 +public: // static visitor interfaces, cont.
    1.76 +
    1.77 +    result_type operator()(argument_fwd_type operand) const
    1.78 +    {
    1.79 +        return visitor_(operand);
    1.80 +    }
    1.81 +
    1.82 +#else // defined(BOOST_NO_VOID_RETURNS)
    1.83 +
    1.84 +private: // helpers, for static visitor interfaces (below)
    1.85 +
    1.86 +    result_type execute_impl(argument_fwd_type operand, mpl::false_) const
    1.87 +    {
    1.88 +        return visitor_(operand);
    1.89 +    }
    1.90 +
    1.91 +        BOOST_VARIANT_AUX_RETURN_VOID_TYPE
    1.92 +    execute_impl(argument_fwd_type operand, mpl::true_) const
    1.93 +    {
    1.94 +        visitor_(operand);
    1.95 +        BOOST_VARIANT_AUX_RETURN_VOID;
    1.96 +    }
    1.97 +
    1.98 +public: // static visitor interfaces, cont.
    1.99 +
   1.100 +        BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(result_type)
   1.101 +    operator()(argument_fwd_type operand) const
   1.102 +    {
   1.103 +        typedef typename is_void<result_type>::type has_void_result;
   1.104 +        return execute_impl(operand, has_void_result());
   1.105 +    }
   1.106 +
   1.107 +#endif // BOOST_NO_VOID_RETURNS workaround
   1.108 +
   1.109 +};
   1.110 +
   1.111 +template <typename R, typename T>
   1.112 +inline visitor_ptr_t<T,R> visitor_ptr(R (*visitor)(T))
   1.113 +{
   1.114 +    return visitor_ptr_t<T,R>(visitor);
   1.115 +}
   1.116 +
   1.117 +} // namespace boost
   1.118 +
   1.119 +#endif// BOOST_VISITOR_VISITOR_PTR_HPP