blob: a1aff54f05be87c1b305f85c3e0fc8ec8a4212ee (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
// boost lockfree: copy_payload helper
//
// Copyright (C) 2011 Tim Blechmann
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_LOCKFREE_DETAIL_COPY_PAYLOAD_HPP_INCLUDED
#define BOOST_LOCKFREE_DETAIL_COPY_PAYLOAD_HPP_INCLUDED
#include <boost/mpl/if.hpp>
#include <boost/type_traits/is_convertible.hpp>
namespace boost {
namespace lockfree {
namespace detail {
struct copy_convertible
{
template <typename T, typename U>
static void copy(T & t, U & u)
{
u = t;
}
};
struct copy_constructible_and_copyable
{
template <typename T, typename U>
static void copy(T & t, U & u)
{
u = U(t);
}
};
template <typename T, typename U>
void copy_payload(T & t, U & u)
{
typedef typename boost::mpl::if_<typename boost::is_convertible<T, U>::type,
copy_convertible,
copy_constructible_and_copyable
>::type copy_type;
copy_type::copy(t, u);
}
template <typename T>
struct consume_via_copy
{
consume_via_copy(T & out):
out_(out)
{}
template <typename U>
void operator()(U & element)
{
copy_payload(element, out_);
}
T & out_;
};
struct consume_noop
{
template <typename U>
void operator()(const U &)
{
}
};
}}}
#endif /* BOOST_LOCKFREE_DETAIL_COPY_PAYLOAD_HPP_INCLUDED */
|