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