Mercurial > hg > vamp-build-and-test
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DEPENDENCIES/generic/include/boost/lockfree/detail/copy_payload.hpp Tue Aug 05 11:11:38 2014 +0100 @@ -0,0 +1,66 @@ +// 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; +}; + + +}}} + +#endif /* BOOST_LOCKFREE_DETAIL_COPY_PAYLOAD_HPP_INCLUDED */