1 /*=============================================================================
2 Copyright (c) 2001-2014 Joel de Guzman
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 =============================================================================*/
7 #if !defined(BOOST_SPIRIT_X3_CALL_CONTEXT_MAY_26_2014_0234PM)
8 #define BOOST_SPIRIT_X3_CALL_CONTEXT_MAY_26_2014_0234PM
10 #include <type_traits>
12 #include <boost/spirit/home/x3/support/context.hpp>
13 #include <boost/spirit/home/x3/support/utility/is_callable.hpp>
14 #include <boost/range/iterator_range_core.hpp>
16 namespace boost { namespace spirit { namespace x3
18 ////////////////////////////////////////////////////////////////////////////
19 struct rule_val_context_tag;
21 template <typename Context>
22 inline decltype(auto) _val(Context const& context)
24 return x3::get<rule_val_context_tag>(context);
27 ////////////////////////////////////////////////////////////////////////////
28 struct where_context_tag;
30 template <typename Context>
31 inline decltype(auto) _where(Context const& context)
33 return x3::get<where_context_tag>(context);
36 ////////////////////////////////////////////////////////////////////////////
37 struct attr_context_tag;
39 template <typename Context>
40 inline decltype(auto) _attr(Context const& context)
42 return x3::get<attr_context_tag>(context);
45 ////////////////////////////////////////////////////////////////////////////
48 template <typename F, typename Context>
49 auto call(F f, Context const& context, mpl::true_)
54 template <typename F, typename Context>
55 auto call(F f, Context const& /* context */, mpl::false_)
62 typename F, typename Iterator
63 , typename Context, typename RuleContext, typename Attribute>
65 F f, Iterator& first, Iterator const& last
66 , Context const& context, RuleContext& rcontext, Attribute& attr)
68 boost::iterator_range<Iterator> rng(first, last);
69 auto val_context = make_context<rule_val_context_tag>(rcontext, context);
70 auto where_context = make_context<where_context_tag>(rng, val_context);
71 auto attr_context = make_context<attr_context_tag>(attr, where_context);
72 return detail::call(f, attr_context, is_callable<F(decltype(attr_context) const&)>());