Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:02:35

0001 /*=============================================================================
0002     Copyright (c) 2001-2014 Joel de Guzman
0003 
0004     Distributed under the Boost Software License, Version 1.0. (See accompanying
0005     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 =============================================================================*/
0007 #if !defined(BOOST_SPIRIT_X3_CALL_CONTEXT_MAY_26_2014_0234PM)
0008 #define BOOST_SPIRIT_X3_CALL_CONTEXT_MAY_26_2014_0234PM
0009 
0010 #include <type_traits>
0011 
0012 #include <boost/spirit/home/x3/support/context.hpp>
0013 #include <boost/spirit/home/x3/support/utility/is_callable.hpp>
0014 #include <boost/range/iterator_range_core.hpp>
0015 
0016 namespace boost { namespace spirit { namespace x3
0017 {
0018     ////////////////////////////////////////////////////////////////////////////
0019     struct rule_val_context_tag;
0020 
0021     template <typename Context>
0022     inline decltype(auto) _val(Context const& context)
0023     {
0024         return x3::get<rule_val_context_tag>(context);
0025     }
0026 
0027     ////////////////////////////////////////////////////////////////////////////
0028     struct where_context_tag;
0029 
0030     template <typename Context>
0031     inline decltype(auto) _where(Context const& context)
0032     {
0033         return x3::get<where_context_tag>(context);
0034     }
0035 
0036     ////////////////////////////////////////////////////////////////////////////
0037     struct attr_context_tag;
0038 
0039     template <typename Context>
0040     inline decltype(auto) _attr(Context const& context)
0041     {
0042         return x3::get<attr_context_tag>(context);
0043     }
0044 
0045     ////////////////////////////////////////////////////////////////////////////
0046     namespace detail
0047     {
0048         template <typename F, typename Context>
0049         auto call(F f, Context const& context, mpl::true_)
0050         {
0051             return f(context);
0052         }
0053 
0054         template <typename F, typename Context>
0055         auto call(F f, Context const& /* context */, mpl::false_)
0056         {
0057             return f();
0058         }
0059     }
0060 
0061     template <
0062         typename F, typename Iterator
0063       , typename Context, typename RuleContext, typename Attribute>
0064     auto call(
0065         F f, Iterator& first, Iterator const& last
0066       , Context const& context, RuleContext& rcontext, Attribute& attr)
0067     {
0068         boost::iterator_range<Iterator> rng(first, last);
0069         auto val_context = make_context<rule_val_context_tag>(rcontext, context);
0070         auto where_context = make_context<where_context_tag>(rng, val_context);
0071         auto attr_context = make_context<attr_context_tag>(attr, where_context);
0072         return detail::call(f, attr_context, is_callable<F(decltype(attr_context) const&)>());
0073     }
0074 }}}
0075 
0076 #endif