Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /*=============================================================================
0002     Copyright (c) 2001-2014 Joel de Guzman
0003     http://spirit.sourceforge.net/
0004 
0005     Distributed under the Boost Software License, Version 1.0. (See accompanying
0006     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 =============================================================================*/
0008 #if !defined(BOOST_SPIRIT_X3_CONTEXT_JAN_4_2012_1215PM)
0009 #define BOOST_SPIRIT_X3_CONTEXT_JAN_4_2012_1215PM
0010 
0011 #include <boost/spirit/home/x3/support/unused.hpp>
0012 #include <boost/mpl/identity.hpp>
0013 
0014 namespace boost { namespace spirit { namespace x3
0015 {
0016     template <typename ID, typename T, typename Next = unused_type>
0017     struct context
0018     {
0019         context(T& val, Next const& next)
0020             : val(val), next(next) {}
0021 
0022         T& get(mpl::identity<ID>) const
0023         {
0024             return val;
0025         }
0026 
0027         template <typename ID_>
0028         decltype(auto) get(ID_ id) const
0029         {
0030             return next.get(id);
0031         }
0032 
0033         T& val;
0034         Next const& next;
0035     };
0036 
0037     template <typename ID, typename T>
0038     struct context<ID, T, unused_type>
0039     {
0040         context(T& val)
0041             : val(val) {}
0042 
0043         context(T& val, unused_type)
0044             : val(val) {}
0045 
0046         T& get(mpl::identity<ID>) const
0047         {
0048             return val;
0049         }
0050 
0051         template <typename ID_>
0052         unused_type get(ID_) const
0053         {
0054             return {};
0055         }
0056 
0057         T& val;
0058     };
0059 
0060     template <typename Tag, typename Context>
0061     inline decltype(auto) get(Context const& context)
0062     {
0063         return context.get(mpl::identity<Tag>());
0064     }
0065 
0066     template <typename ID, typename T, typename Next>
0067     inline context<ID, T, Next> make_context(T& val, Next const& next)
0068     {
0069         return { val, next };
0070     }
0071 
0072     template <typename ID, typename T>
0073     inline context<ID, T> make_context(T& val)
0074     {
0075         return { val };
0076     }
0077 
0078     namespace detail
0079     {
0080         template <typename ID, typename T, typename Next, typename FoundVal>
0081         inline Next const&
0082         make_unique_context(T& /* val */, Next const& next, FoundVal&)
0083         {
0084             return next;
0085         }
0086         
0087         template <typename ID, typename T, typename Next>
0088         inline context<ID, T, Next>
0089         make_unique_context(T& val, Next const& next, unused_type)
0090         {
0091             return { val, next };
0092         }
0093     }
0094 
0095     template <typename ID, typename T, typename Next>
0096     inline auto
0097     make_unique_context(T& val, Next const& next)
0098     {
0099         return detail::make_unique_context<ID>(val, next, x3::get<ID>(next));
0100     }
0101 }}}
0102 
0103 #endif