Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:31:16

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(FUSION_REPLACE_IF_08182005_0946)
0008 #define FUSION_REPLACE_IF_08182005_0946
0009 
0010 #include <boost/fusion/support/config.hpp>
0011 #include <boost/utility/enable_if.hpp>
0012 #include <boost/mpl/if.hpp>
0013 #include <boost/type_traits/remove_reference.hpp>
0014 
0015 namespace boost { namespace fusion { namespace detail
0016 {
0017     template <bool is_convertible>
0018     struct replacer_if_helper;
0019 
0020     template <>
0021     struct replacer_if_helper<false>
0022     {
0023         template <typename U, typename F, typename T>
0024         BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0025         static U&
0026         call(U& x, F&, T const&)
0027         {
0028             return x;
0029         }
0030     };
0031 
0032     template <>
0033     struct replacer_if_helper<true>
0034     {
0035         template <typename U, typename F, typename T>
0036         BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0037         static U
0038         call(U& x, F& f, T const& new_value)
0039         {
0040             return f(x) ? new_value : x;
0041         }
0042     };
0043 
0044     template <typename F, typename T>
0045     struct replacer_if
0046     {
0047         BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0048         replacer_if(F in_f, T const& in_new_value)
0049             : f(in_f), new_value(in_new_value) {}
0050 
0051         template<typename Params>
0052         struct result;
0053 
0054         template <typename F1, typename T1, typename U>
0055         struct result<replacer_if<F1, T1>(U)>
0056         {
0057             typedef typename remove_reference<U>::type value;
0058             typedef typename
0059                 mpl::if_<is_convertible<T, value>, value, value const&>::type
0060             type;
0061         };
0062 
0063         template <typename U>
0064         BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0065         typename result<replacer_if(U)>::type
0066         operator()(U const& x) const
0067         {
0068             return replacer_if_helper<is_convertible<T, U>::value>::
0069                 call(x, f, new_value);
0070         }
0071 
0072         F f;
0073         T new_value;
0074     };
0075 }}}
0076 
0077 #endif
0078