5f5642bf933086135da5d19fed9c12466938b92d
[platform/upstream/boost.git] / boost / variant / detail / apply_visitor_delayed.hpp
1 //-----------------------------------------------------------------------------
2 // boost variant/detail/apply_visitor_delayed.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_DELAYED_HPP
14 #define BOOST_VARIANT_DETAIL_APPLY_VISITOR_DELAYED_HPP
15
16 #include "boost/variant/detail/generic_result_type.hpp"
17
18 #include "boost/variant/detail/apply_visitor_unary.hpp"
19 #include "boost/variant/detail/apply_visitor_binary.hpp"
20
21 namespace boost {
22
23 //////////////////////////////////////////////////////////////////////////
24 // function template apply_visitor(visitor)
25 //
26 // Returns a function object, overloaded for unary and binary usage, that
27 // visits its arguments using visitor (or a copy of visitor) via
28 //  * apply_visitor( visitor, [argument] )
29 // under unary invocation, or
30 //  * apply_visitor( visitor, [argument1], [argument2] )
31 // under binary invocation.
32 //
33 // NOTE: Unlike other apply_visitor forms, the visitor object must be
34 //   non-const; this prevents user from giving temporary, to disastrous
35 //   effect (i.e., returned function object would have dead reference).
36 //
37
38 template <typename Visitor>
39 class apply_visitor_delayed_t
40 {
41 public: // visitor typedefs
42
43     typedef typename Visitor::result_type
44         result_type;
45
46 private: // representation
47
48     Visitor& visitor_;
49
50 public: // structors
51
52     explicit apply_visitor_delayed_t(Visitor& visitor)
53       : visitor_(visitor)
54     {
55     }
56
57 public: // unary visitor interface
58
59     template <typename Visitable>
60         BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(result_type)
61     operator()(Visitable& visitable) const
62     {
63         return apply_visitor(visitor_, visitable);
64     }
65
66 public: // binary visitor interface
67
68     template <typename Visitable1, typename Visitable2>
69         BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(result_type)
70     operator()(Visitable1& visitable1, Visitable2& visitable2) const
71     {
72         return apply_visitor(visitor_, visitable1, visitable2);
73     }
74
75 private:
76     apply_visitor_delayed_t& operator=(const apply_visitor_delayed_t&);
77
78 };
79
80 template <typename Visitor>
81 inline apply_visitor_delayed_t<Visitor> apply_visitor(Visitor& visitor)
82 {
83     return apply_visitor_delayed_t<Visitor>(visitor);
84 }
85
86 } // namespace boost
87
88 #endif // BOOST_VARIANT_DETAIL_APPLY_VISITOR_DELAYED_HPP