1 // Copyright (c) 2001-2011 Hartmut Kaiser
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #if !defined(BOOST_SPIRIT_KARMA_PHOENIX_ATTRIBUTES_OCT_01_2009_1128AM)
7 #define BOOST_SPIRIT_KARMA_PHOENIX_ATTRIBUTES_OCT_01_2009_1128AM
13 #include <boost/spirit/include/version.hpp>
15 // we support Phoenix attributes only starting with V2.2
16 #if SPIRIT_VERSION >= 0x2020
18 #include <boost/spirit/home/karma/detail/attributes.hpp>
19 #include <boost/spirit/home/karma/detail/indirect_iterator.hpp>
20 #include <boost/spirit/home/support/container.hpp>
22 #include <boost/utility/result_of.hpp>
24 ///////////////////////////////////////////////////////////////////////////////
25 namespace boost { namespace phoenix
27 template <typename Expr>
31 ///////////////////////////////////////////////////////////////////////////////
32 namespace boost { namespace spirit { namespace traits
34 ///////////////////////////////////////////////////////////////////////////
35 // Provide customization points allowing the use of phoenix expressions as
36 // generator functions in the context of generators expecting a container
37 // attribute (Kleene, plus, list, repeat, etc.)
38 ///////////////////////////////////////////////////////////////////////////
39 template <typename Eval>
40 struct is_container<phoenix::actor<Eval> const>
41 : is_container<typename boost::result_of<phoenix::actor<Eval>()>::type>
44 template <typename Eval>
45 struct container_iterator<phoenix::actor<Eval> const>
47 typedef phoenix::actor<Eval> const& type;
50 template <typename Eval>
51 struct begin_container<phoenix::actor<Eval> const>
53 typedef phoenix::actor<Eval> const& type;
54 static type call(phoenix::actor<Eval> const& f)
60 template <typename Eval>
61 struct end_container<phoenix::actor<Eval> const>
63 typedef phoenix::actor<Eval> const& type;
64 static type call(phoenix::actor<Eval> const& f)
70 template <typename Eval>
71 struct deref_iterator<phoenix::actor<Eval> const>
73 typedef typename boost::result_of<phoenix::actor<Eval>()>::type type;
74 static type call(phoenix::actor<Eval> const& f)
80 template <typename Eval>
81 struct next_iterator<phoenix::actor<Eval> const>
83 typedef phoenix::actor<Eval> const& type;
84 static type call(phoenix::actor<Eval> const& f)
90 template <typename Eval>
91 struct compare_iterators<phoenix::actor<Eval> const>
94 call(phoenix::actor<Eval> const&, phoenix::actor<Eval> const&)
100 template <typename Eval>
101 struct container_value<phoenix::actor<Eval> >
103 typedef phoenix::actor<Eval> const& type;
106 template <typename Eval>
107 struct make_indirect_iterator<phoenix::actor<Eval> const>
109 typedef phoenix::actor<Eval> const& type;
112 ///////////////////////////////////////////////////////////////////////////
113 // Handle Phoenix actors as attributes, just invoke the function object
114 // and deal with the result as the attribute.
115 ///////////////////////////////////////////////////////////////////////////
116 template <typename Eval, typename Exposed>
117 struct extract_from_attribute<phoenix::actor<Eval>, Exposed>
119 typedef typename boost::result_of<phoenix::actor<Eval>()>::type type;
121 template <typename Context>
122 static type call(phoenix::actor<Eval> const& f, Context& context)
124 return f(unused, context);