]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/fusion/include/boost/fusion/algorithm/transformation/detail/replace.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / fusion / include / boost / fusion / algorithm / transformation / detail / replace.hpp
1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
3
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
9
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>
14
15 namespace boost { namespace fusion { namespace detail
16 {
17 template <bool is_convertible>
18 struct replacer_helper;
19
20 template <>
21 struct replacer_helper<false>
22 {
23 template <typename U, typename T>
24 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
25 static U&
26 call(U& x, T const&, T const&)
27 {
28 return x;
29 }
30 };
31
32 template <>
33 struct replacer_helper<true>
34 {
35 template <typename U, typename T>
36 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
37 static U
38 call(U& x, T const& old_value, T const& new_value)
39 {
40 return (x == old_value) ? new_value : x;
41 }
42 };
43
44 template <typename T>
45 struct replacer
46 {
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) {}
50
51 template<typename Sig>
52 struct result;
53
54 template <typename U1, typename U2>
55 struct result<replacer<U1>(U2)>
56 {
57 typedef typename remove_reference<U2>::type value;
58 typedef typename
59 mpl::if_<is_convertible<T, value>, value, value const&>::type
60 type;
61 };
62
63 template <typename U>
64 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
65 typename result<replacer(U)>::type
66 operator()(U const& x) const
67 {
68 return replacer_helper<is_convertible<T, U>::value>::
69 call(x, old_value, new_value);
70 }
71
72 T old_value;
73 T new_value;
74 };
75 }}}
76
77 #endif
78