PageRenderTime 12ms CodeModel.GetById 1ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/fusion/algorithm/transformation/detail/replace.hpp

http://hadesmem.googlecode.com/
C++ Header | 73 lines | 56 code | 11 blank | 6 comment | 1 complexity | 934a1a432608566f22b4dd3cfd1ac006 MD5 | raw file
 1/*=============================================================================
 2    Copyright (c) 2001-2006 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/type_traits/is_convertible.hpp>
11#include <boost/mpl/if.hpp>
12#include <boost/type_traits/remove_reference.hpp>
13
14namespace boost { namespace fusion { namespace detail
15{
16    template <bool is_convertible>
17    struct replacer_helper;
18
19    template <>
20    struct replacer_helper<false>
21    {
22        template <typename U, typename T>
23        static U&
24        call(U& x, T const&, T const&)
25        {
26            return x;
27        }
28    };
29
30    template <>
31    struct replacer_helper<true>
32    {
33        template <typename U, typename T>
34        static U
35        call(U& x, T const& old_value, T const& new_value)
36        {
37            return (x == old_value) ? new_value : x;
38        }
39    };
40
41    template <typename T>
42    struct replacer
43    {
44        replacer(T const& in_old_value, T const& in_new_value)
45            : old_value(in_old_value), new_value(in_new_value) {}
46
47        template<typename Sig>
48        struct result;
49
50        template <typename U1, typename U2>
51        struct result<replacer<U1>(U2)>
52        {
53            typedef typename remove_reference<U2>::type value;
54            typedef typename
55                mpl::if_<is_convertible<T, value>, value, value const&>::type
56            type;
57        };
58    
59        template <typename U>
60        typename result<replacer(U)>::type
61        operator()(U const& x) const
62        {
63            return replacer_helper<is_convertible<T, U>::value>::
64                call(x, old_value, new_value);
65        }
66
67        T old_value;
68        T new_value;
69    };
70}}}
71
72#endif
73