]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/fusion/algorithm/transformation/detail/replace_if.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / fusion / algorithm / transformation / detail / replace_if.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_IF_08182005_0946)
8 #define FUSION_REPLACE_IF_08182005_0946
9
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>
14
15 namespace boost { namespace fusion { namespace detail
16 {
17 template <bool is_convertible>
18 struct replacer_if_helper;
19
20 template <>
21 struct replacer_if_helper<false>
22 {
23 template <typename U, typename F, typename T>
24 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
25 static U&
26 call(U& x, F&, T const&)
27 {
28 return x;
29 }
30 };
31
32 template <>
33 struct replacer_if_helper<true>
34 {
35 template <typename U, typename F, typename T>
36 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
37 static U
38 call(U& x, F& f, T const& new_value)
39 {
40 return f(x) ? new_value : x;
41 }
42 };
43
44 template <typename F, typename T>
45 struct replacer_if
46 {
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) {}
50
51 template<typename Params>
52 struct result;
53
54 template <typename F1, typename T1, typename U>
55 struct result<replacer_if<F1, T1>(U)>
56 {
57 typedef typename remove_reference<U>::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_if(U)>::type
66 operator()(U const& x) const
67 {
68 return replacer_if_helper<is_convertible<T, U>::value>::
69 call(x, f, new_value);
70 }
71
72 F f;
73 T new_value;
74 };
75 }}}
76
77 #endif
78