Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/lockfree/detail/copy_payload.hpp @ 16:2665513ce2d3
Add boost headers
author | Chris Cannam |
---|---|
date | Tue, 05 Aug 2014 11:11:38 +0100 |
parents | |
children | c530137014c0 |
comparison
equal
deleted
inserted
replaced
15:663ca0da4350 | 16:2665513ce2d3 |
---|---|
1 // boost lockfree: copy_payload helper | |
2 // | |
3 // Copyright (C) 2011 Tim Blechmann | |
4 // | |
5 // Distributed under the Boost Software License, Version 1.0. (See | |
6 // accompanying file LICENSE_1_0.txt or copy at | |
7 // http://www.boost.org/LICENSE_1_0.txt) | |
8 | |
9 #ifndef BOOST_LOCKFREE_DETAIL_COPY_PAYLOAD_HPP_INCLUDED | |
10 #define BOOST_LOCKFREE_DETAIL_COPY_PAYLOAD_HPP_INCLUDED | |
11 | |
12 #include <boost/mpl/if.hpp> | |
13 #include <boost/type_traits/is_convertible.hpp> | |
14 | |
15 namespace boost { | |
16 namespace lockfree { | |
17 namespace detail { | |
18 | |
19 struct copy_convertible | |
20 { | |
21 template <typename T, typename U> | |
22 static void copy(T & t, U & u) | |
23 { | |
24 u = t; | |
25 } | |
26 }; | |
27 | |
28 struct copy_constructible_and_copyable | |
29 { | |
30 template <typename T, typename U> | |
31 static void copy(T & t, U & u) | |
32 { | |
33 u = U(t); | |
34 } | |
35 }; | |
36 | |
37 template <typename T, typename U> | |
38 void copy_payload(T & t, U & u) | |
39 { | |
40 typedef typename boost::mpl::if_<typename boost::is_convertible<T, U>::type, | |
41 copy_convertible, | |
42 copy_constructible_and_copyable | |
43 >::type copy_type; | |
44 copy_type::copy(t, u); | |
45 } | |
46 | |
47 template <typename T> | |
48 struct consume_via_copy | |
49 { | |
50 consume_via_copy(T & out): | |
51 out(out) | |
52 {} | |
53 | |
54 template <typename U> | |
55 void operator()(U & element) | |
56 { | |
57 copy_payload(element, out); | |
58 } | |
59 | |
60 T & out; | |
61 }; | |
62 | |
63 | |
64 }}} | |
65 | |
66 #endif /* BOOST_LOCKFREE_DETAIL_COPY_PAYLOAD_HPP_INCLUDED */ |