1 /*=============================================================================
2 Copyright (c) 2001-2011 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(FUSION_REPLACE_IF_08182005_0946)
8 #define FUSION_REPLACE_IF_08182005_0946
10 #include <boost/fusion/support/config.hpp>
11 #include <boost/utility/enable_if.hpp>
12 #include <boost/mpl/if.hpp>
13 #include <boost/type_traits/remove_reference.hpp>
15 namespace boost { namespace fusion { namespace detail
17 template <bool is_convertible>
18 struct replacer_if_helper;
21 struct replacer_if_helper<false>
23 template <typename U, typename F, typename T>
24 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
26 call(U& x, F&, T const&)
33 struct replacer_if_helper<true>
35 template <typename U, typename F, typename T>
36 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
38 call(U& x, F& f, T const& new_value)
40 return f(x) ? new_value : x;
44 template <typename F, typename T>
47 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
48 replacer_if(F in_f, T const& in_new_value)
49 : f(in_f), new_value(in_new_value) {}
51 template<typename Params>
54 template <typename F1, typename T1, typename U>
55 struct result<replacer_if<F1, T1>(U)>
57 typedef typename remove_reference<U>::type value;
59 mpl::if_<is_convertible<T, value>, value, value const&>::type
64 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
65 typename result<replacer_if(U)>::type
66 operator()(U const& x) const
68 return replacer_if_helper<is_convertible<T, U>::value>::
69 call(x, f, new_value);