source: NonGTP/Boost/boost/variant/detail/apply_visitor_delayed.hpp @ 857

Revision 857, 2.6 KB checked in by igarcia, 19 years ago (diff)
Line 
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
21namespace 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
38template <typename Visitor>
39class apply_visitor_delayed_t
40{
41public: // visitor typedefs
42
43    typedef typename Visitor::result_type
44        result_type;
45
46private: // representation
47
48    Visitor& visitor_;
49
50public: // structors
51
52    explicit apply_visitor_delayed_t(Visitor& visitor)
53      : visitor_(visitor)
54    {
55    }
56
57public: // unary visitor interface
58
59    template <typename Visitable>
60        BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(result_type)
61    operator()(Visitable& visitable)
62    {
63        return apply_visitor(visitor_, visitable);
64    }
65
66public: // 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)
71    {
72        return apply_visitor(visitor_, visitable1, visitable2);
73    }
74
75};
76
77template <typename Visitor>
78inline apply_visitor_delayed_t<Visitor> apply_visitor(Visitor& visitor)
79{
80    return apply_visitor_delayed_t<Visitor>(visitor);
81}
82
83} // namespace boost
84
85#endif // BOOST_VARIANT_DETAIL_APPLY_VISITOR_DELAYED_HPP
Note: See TracBrowser for help on using the repository browser.