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_08182005_0841)
8 #define FUSION_REPLACE_08182005_0841
10 #include <boost/fusion/support/config.hpp>
11 #include <boost/type_traits/is_convertible.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_helper;
21 struct replacer_helper<false>
23 template <typename U, typename T>
24 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
26 call(U& x, T const&, T const&)
33 struct replacer_helper<true>
35 template <typename U, typename T>
36 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
38 call(U& x, T const& old_value, T const& new_value)
40 return (x == old_value) ? new_value : x;
47 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
48 replacer(T const& in_old_value, T const& in_new_value)
49 : old_value(in_old_value), new_value(in_new_value) {}
51 template<typename Sig>
54 template <typename U1, typename U2>
55 struct result<replacer<U1>(U2)>
57 typedef typename remove_reference<U2>::type value;
59 mpl::if_<is_convertible<T, value>, value, value const&>::type
64 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
65 typename result<replacer(U)>::type
66 operator()(U const& x) const
68 return replacer_helper<is_convertible<T, U>::value>::
69 call(x, old_value, new_value);