Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/spirit/home/support/nonterminal/expand_arg.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*=============================================================================
0002     Copyright (c) 2001-2011 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_EXPAND_ARG_FEB_19_2007_1107AM)
0008 #define BOOST_SPIRIT_EXPAND_ARG_FEB_19_2007_1107AM
0009 
0010 #if defined(_MSC_VER)
0011 #pragma once
0012 #endif
0013 
0014 #include <boost/mpl/bool.hpp>
0015 #include <boost/mpl/or.hpp>
0016 #include <boost/mpl/identity.hpp>
0017 #include <boost/mpl/eval_if.hpp>
0018 #include <boost/utility/result_of.hpp>
0019 #include <boost/type_traits/is_scalar.hpp>
0020 #include <boost/spirit/home/support/string_traits.hpp>
0021 
0022 namespace boost { namespace spirit { namespace detail
0023 {
0024     ///////////////////////////////////////////////////////////////////////////
0025 #ifdef _MSC_VER
0026 #  pragma warning(push)
0027 #  pragma warning(disable: 4512) // assignment operator could not be generated.
0028 #endif
0029     template <typename Context>
0030     struct expand_arg
0031     {
0032         template <typename T>
0033         struct result_type
0034         {
0035             // This is a temporary hack. The better way is to detect if T
0036             // can be called given unused context.
0037             typedef typename
0038                 mpl::eval_if<
0039                     mpl::or_<is_scalar<T>, traits::is_string<T> >
0040                   , mpl::identity<T const &>
0041                   , boost::result_of<T(unused_type, Context)>
0042                 >::type
0043             type;
0044         };
0045 
0046         template <typename T>
0047         struct result;
0048 
0049         template <typename F, typename A0>
0050         struct result<F(A0)>
0051           : result_type<A0> {};
0052 
0053         template <typename F, typename A0>
0054         struct result<F(A0&)>
0055           : result_type<A0> {};
0056 
0057         expand_arg(Context& context_)
0058           : context(context_)
0059         {
0060         }
0061 
0062         template <typename T>
0063         typename result_type<T>::type
0064         call(T const& f, mpl::false_) const
0065         {
0066             return f(unused, context);
0067         }
0068 
0069         template <typename T>
0070         typename result_type<T>::type
0071         call(T const& val, mpl::true_) const
0072         {
0073             return val;
0074         }
0075 
0076         template <typename T>
0077         typename result_type<T>::type
0078         operator()(T const& x) const
0079         {
0080             return call(x, mpl::or_<is_scalar<T>, traits::is_string<T> >());
0081         }
0082 
0083         Context& context;
0084     };
0085 #ifdef _MSC_VER
0086 #  pragma warning(pop)
0087 #endif
0088 
0089 }}}
0090 
0091 #endif