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/type_traits/is_convertible.hpp>
11 #include <boost/mpl/if.hpp>
12 #include <boost/type_traits/remove_reference.hpp>
14 namespace boost { namespace fusion { namespace detail
16 template <bool is_convertible>
17 struct replacer_helper;
20 struct replacer_helper<false>
22 template <typename U, typename T>
24 call(U& x, T const&, T const&)
31 struct replacer_helper<true>
33 template <typename U, typename T>
35 call(U& x, T const& old_value, T const& new_value)
37 return (x == old_value) ? new_value : x;
44 replacer(T const& in_old_value, T const& in_new_value)
45 : old_value(in_old_value), new_value(in_new_value) {}
47 template<typename Sig>
50 template <typename U1, typename U2>
51 struct result<replacer<U1>(U2)>
53 typedef typename remove_reference<U2>::type value;
55 mpl::if_<is_convertible<T, value>, value, value const&>::type
60 typename result<replacer(U)>::type
61 operator()(U const& x) const
63 return replacer_helper<is_convertible<T, U>::value>::
64 call(x, old_value, new_value);