PageRenderTime 25ms CodeModel.GetById 17ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/variant/detail/apply_visitor_binary.hpp

http://hadesmem.googlecode.com/
C++ Header | 182 lines | 111 code | 45 blank | 26 comment | 0 complexity | 64c7a2af94b21f53765e437fa4fcaed8 MD5 | raw file
  1//-----------------------------------------------------------------------------
  2// boost variant/detail/apply_visitor_binary.hpp header file
  3// See http://www.boost.org for updates, documentation, and revision history.
  4//-----------------------------------------------------------------------------
  5//
  6// Copyright (c) 2002-2003
  7// Eric Friedman
  8//
  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)
 12
 13#ifndef BOOST_VARIANT_DETAIL_APPLY_VISITOR_BINARY_HPP
 14#define BOOST_VARIANT_DETAIL_APPLY_VISITOR_BINARY_HPP
 15
 16#include "boost/config.hpp"
 17#include "boost/detail/workaround.hpp"
 18#include "boost/variant/detail/generic_result_type.hpp"
 19
 20#include "boost/variant/detail/apply_visitor_unary.hpp"
 21
 22#if BOOST_WORKAROUND(__EDG__, BOOST_TESTED_AT(302))
 23#include "boost/utility/enable_if.hpp"
 24#include "boost/mpl/not.hpp"
 25#include "boost/type_traits/is_const.hpp"
 26#endif
 27
 28namespace boost {
 29
 30//////////////////////////////////////////////////////////////////////////
 31// function template apply_visitor(visitor, visitable1, visitable2)
 32//
 33// Visits visitable1 and visitable2 such that their values (which we
 34// shall call x and y, respectively) are used as arguments in the
 35// expression visitor(x, y).
 36//
 37
 38namespace detail { namespace variant {
 39
 40template <typename Visitor, typename Value1>
 41class apply_visitor_binary_invoke
 42{
 43public: // visitor typedefs
 44
 45    typedef typename Visitor::result_type
 46        result_type;
 47
 48private: // representation
 49
 50    Visitor& visitor_;
 51    Value1& value1_;
 52
 53public: // structors
 54
 55    apply_visitor_binary_invoke(Visitor& visitor, Value1& value1)
 56        : visitor_(visitor)
 57        , value1_(value1)
 58    {
 59    }
 60
 61public: // visitor interfaces
 62
 63    template <typename Value2>
 64        BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(result_type)
 65    operator()(Value2& value2)
 66    {
 67        return visitor_(value1_, value2);
 68    }
 69
 70private:
 71    apply_visitor_binary_invoke& operator=(const apply_visitor_binary_invoke&);
 72
 73};
 74
 75template <typename Visitor, typename Visitable2>
 76class apply_visitor_binary_unwrap
 77{
 78public: // visitor typedefs
 79
 80    typedef typename Visitor::result_type
 81        result_type;
 82
 83private: // representation
 84
 85    Visitor& visitor_;
 86    Visitable2& visitable2_;
 87
 88public: // structors
 89
 90    apply_visitor_binary_unwrap(Visitor& visitor, Visitable2& visitable2)
 91        : visitor_(visitor)
 92        , visitable2_(visitable2)
 93    {
 94    }
 95
 96public: // visitor interfaces
 97
 98    template <typename Value1>
 99        BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(result_type)
100    operator()(Value1& value1)
101    {
102        apply_visitor_binary_invoke<
103              Visitor
104            , Value1
105            > invoker(visitor_, value1);
106
107        return boost::apply_visitor(invoker, visitable2_);
108    }
109
110private:
111    apply_visitor_binary_unwrap& operator=(const apply_visitor_binary_unwrap&);
112
113};
114
115}} // namespace detail::variant
116
117//
118// nonconst-visitor version:
119//
120
121#if !BOOST_WORKAROUND(__EDG__, BOOST_TESTED_AT(302))
122
123#   define BOOST_VARIANT_AUX_APPLY_VISITOR_NON_CONST_RESULT_TYPE(V) \
124    BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(typename V::result_type) \
125    /**/
126
127#else // EDG-based compilers
128
129#   define BOOST_VARIANT_AUX_APPLY_VISITOR_NON_CONST_RESULT_TYPE(V) \
130    typename enable_if< \
131          mpl::not_< is_const< V > > \
132        , BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(typename V::result_type) \
133        >::type \
134    /**/
135
136#endif // EDG-based compilers workaround
137
138template <typename Visitor, typename Visitable1, typename Visitable2>
139inline
140    BOOST_VARIANT_AUX_APPLY_VISITOR_NON_CONST_RESULT_TYPE(Visitor)
141apply_visitor(
142      Visitor& visitor
143    , Visitable1& visitable1, Visitable2& visitable2
144    )
145{
146    ::boost::detail::variant::apply_visitor_binary_unwrap<
147          Visitor, Visitable2
148        > unwrapper(visitor, visitable2);
149
150    return boost::apply_visitor(unwrapper, visitable1);
151}
152
153#undef BOOST_VARIANT_AUX_APPLY_VISITOR_NON_CONST_RESULT_TYPE
154
155//
156// const-visitor version:
157//
158
159#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
160
161template <typename Visitor, typename Visitable1, typename Visitable2>
162inline
163    BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(
164          typename Visitor::result_type
165        )
166apply_visitor(
167      const Visitor& visitor
168    , Visitable1& visitable1, Visitable2& visitable2
169    )
170{
171    ::boost::detail::variant::apply_visitor_binary_unwrap<
172          const Visitor, Visitable2
173        > unwrapper(visitor, visitable2);
174
175    return boost::apply_visitor(unwrapper, visitable1);
176}
177
178#endif // MSVC7 and below exclusion
179
180} // namespace boost
181
182#endif // BOOST_VARIANT_DETAIL_APPLY_VISITOR_BINARY_HPP