File indexing completed on 2025-01-18 09:31:16
0001
0002
0003
0004
0005
0006
0007 #if !defined(FUSION_REPLACE_08182005_0841)
0008 #define FUSION_REPLACE_08182005_0841
0009
0010 #include <boost/fusion/support/config.hpp>
0011 #include <boost/type_traits/is_convertible.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_helper;
0019
0020 template <>
0021 struct replacer_helper<false>
0022 {
0023 template <typename U, typename T>
0024 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0025 static U&
0026 call(U& x, T const&, T const&)
0027 {
0028 return x;
0029 }
0030 };
0031
0032 template <>
0033 struct replacer_helper<true>
0034 {
0035 template <typename U, typename T>
0036 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0037 static U
0038 call(U& x, T const& old_value, T const& new_value)
0039 {
0040 return (x == old_value) ? new_value : x;
0041 }
0042 };
0043
0044 template <typename T>
0045 struct replacer
0046 {
0047 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0048 replacer(T const& in_old_value, T const& in_new_value)
0049 : old_value(in_old_value), new_value(in_new_value) {}
0050
0051 template<typename Sig>
0052 struct result;
0053
0054 template <typename U1, typename U2>
0055 struct result<replacer<U1>(U2)>
0056 {
0057 typedef typename remove_reference<U2>::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(U)>::type
0066 operator()(U const& x) const
0067 {
0068 return replacer_helper<is_convertible<T, U>::value>::
0069 call(x, old_value, new_value);
0070 }
0071
0072 T old_value;
0073 T new_value;
0074 };
0075 }}}
0076
0077 #endif
0078