epoc32/include/stdapis/boost/variant/get.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/get.hpp	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,202 @@
     1.4 +//-----------------------------------------------------------------------------
     1.5 +// boost variant/get.hpp header file
     1.6 +// See http://www.boost.org for updates, documentation, and revision history.
     1.7 +//-----------------------------------------------------------------------------
     1.8 +//
     1.9 +// Copyright (c) 2003
    1.10 +// Eric Friedman, Itay Maman
    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_GET_HPP
    1.17 +#define BOOST_VARIANT_GET_HPP
    1.18 +
    1.19 +#include <exception>
    1.20 +
    1.21 +#include "boost/config.hpp"
    1.22 +#include "boost/detail/workaround.hpp"
    1.23 +#include "boost/utility/addressof.hpp"
    1.24 +#include "boost/variant/variant_fwd.hpp"
    1.25 +
    1.26 +#include "boost/type_traits/add_reference.hpp"
    1.27 +#include "boost/type_traits/add_pointer.hpp"
    1.28 +
    1.29 +#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
    1.30 +#   include "boost/mpl/bool.hpp"
    1.31 +#   include "boost/mpl/or.hpp"
    1.32 +#   include "boost/type_traits/is_same.hpp"
    1.33 +#endif
    1.34 +
    1.35 +namespace boost {
    1.36 +
    1.37 +//////////////////////////////////////////////////////////////////////////
    1.38 +// class bad_get
    1.39 +//
    1.40 +// The exception thrown in the event of a failed get of a value.
    1.41 +//
    1.42 +class bad_get
    1.43 +    : public std::exception
    1.44 +{
    1.45 +public: // std::exception implementation
    1.46 +
    1.47 +    virtual const char * what() const throw()
    1.48 +    {
    1.49 +        return "boost::bad_get: "
    1.50 +               "failed value get using boost::get";
    1.51 +    }
    1.52 +
    1.53 +};
    1.54 +
    1.55 +//////////////////////////////////////////////////////////////////////////
    1.56 +// function template get<T>
    1.57 +//
    1.58 +// Retrieves content of given variant object if content is of type T.
    1.59 +// Otherwise: pointer ver. returns 0; reference ver. throws bad_get.
    1.60 +//
    1.61 +
    1.62 +namespace detail { namespace variant {
    1.63 +
    1.64 +// (detail) class template get_visitor
    1.65 +//
    1.66 +// Generic static visitor that: if the value is of the specified type,
    1.67 +// returns a pointer to the value it visits; else a null pointer.
    1.68 +//
    1.69 +template <typename T>
    1.70 +struct get_visitor
    1.71 +{
    1.72 +private: // private typedefs
    1.73 +
    1.74 +    typedef typename add_pointer<T>::type pointer;
    1.75 +    typedef typename add_reference<T>::type reference;
    1.76 +
    1.77 +public: // visitor typedefs
    1.78 +
    1.79 +    typedef pointer result_type;
    1.80 +
    1.81 +public: // visitor interfaces
    1.82 +
    1.83 +#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
    1.84 +
    1.85 +    pointer operator()(reference operand) const
    1.86 +    {
    1.87 +        return boost::addressof(operand);
    1.88 +    }
    1.89 +
    1.90 +    template <typename U>
    1.91 +    pointer operator()(const U&) const
    1.92 +    {
    1.93 +        return static_cast<pointer>(0);
    1.94 +    }
    1.95 +
    1.96 +#else // MSVC6
    1.97 +
    1.98 +private: // helpers, for visitor interfaces (below)
    1.99 +
   1.100 +    pointer execute_impl(reference operand, mpl::true_) const
   1.101 +    {
   1.102 +        return boost::addressof(operand);
   1.103 +    }
   1.104 +
   1.105 +    template <typename U>
   1.106 +    pointer execute_impl(const U& operand, mpl::false_) const
   1.107 +    {
   1.108 +        return static_cast<pointer>(0);
   1.109 +    }
   1.110 +
   1.111 +public: // visitor interfaces
   1.112 +
   1.113 +    template <typename U>
   1.114 +    pointer operator()(U& operand) const
   1.115 +    {
   1.116 +        // MSVC6 finds normal implementation (above) ambiguous,
   1.117 +        // so we must explicitly disambiguate
   1.118 +
   1.119 +        typedef typename mpl::or_<
   1.120 +              is_same<U, T>
   1.121 +            , is_same<const U, T>
   1.122 +            >::type U_is_T;
   1.123 +
   1.124 +        return execute_impl(operand, U_is_T());
   1.125 +    }
   1.126 +
   1.127 +#endif // MSVC6 workaround
   1.128 +
   1.129 +};
   1.130 +
   1.131 +}} // namespace detail::variant
   1.132 +
   1.133 +#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x0551))
   1.134 +#   define BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(t)  \
   1.135 +    BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(t)
   1.136 +#else
   1.137 +#   define BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(t)  \
   1.138 +    , t* = 0
   1.139 +#endif
   1.140 +
   1.141 +template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
   1.142 +inline
   1.143 +    typename add_pointer<U>::type
   1.144 +get(
   1.145 +      boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >* operand
   1.146 +      BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
   1.147 +    )
   1.148 +{
   1.149 +    typedef typename add_pointer<U>::type U_ptr;
   1.150 +    if (!operand) return static_cast<U_ptr>(0);
   1.151 +
   1.152 +    detail::variant::get_visitor<U> v;
   1.153 +    return operand->apply_visitor(v);
   1.154 +}
   1.155 +
   1.156 +template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
   1.157 +inline
   1.158 +    typename add_pointer<const U>::type
   1.159 +get(
   1.160 +      const boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >* operand
   1.161 +      BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
   1.162 +    )
   1.163 +{
   1.164 +    typedef typename add_pointer<const U>::type U_ptr;
   1.165 +    if (!operand) return static_cast<U_ptr>(0);
   1.166 +
   1.167 +    detail::variant::get_visitor<const U> v;
   1.168 +    return operand->apply_visitor(v);
   1.169 +}
   1.170 +
   1.171 +template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
   1.172 +inline
   1.173 +    typename add_reference<U>::type
   1.174 +get(
   1.175 +      boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >& operand
   1.176 +      BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
   1.177 +    )
   1.178 +{
   1.179 +    typedef typename add_pointer<U>::type U_ptr;
   1.180 +    U_ptr result = get<U>(&operand);
   1.181 +
   1.182 +    if (!result)
   1.183 +        throw bad_get();
   1.184 +    return *result;
   1.185 +}
   1.186 +
   1.187 +template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
   1.188 +inline
   1.189 +    typename add_reference<const U>::type
   1.190 +get(
   1.191 +      const boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >& operand
   1.192 +      BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
   1.193 +    )
   1.194 +{
   1.195 +    typedef typename add_pointer<const U>::type U_ptr;
   1.196 +    U_ptr result = get<const U>(&operand);
   1.197 +
   1.198 +    if (!result)
   1.199 +        throw bad_get();
   1.200 +    return *result;
   1.201 +}
   1.202 +
   1.203 +} // namespace boost
   1.204 +
   1.205 +#endif // BOOST_VARIANT_GET_HPP