Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:39:17

0001 //  boost lockfree: copy_payload helper
0002 //
0003 //  Copyright (C) 2011, 2016 Tim Blechmann
0004 //
0005 //  Distributed under the Boost Software License, Version 1.0. (See
0006 //  accompanying file LICENSE_1_0.txt or copy at
0007 //  http://www.boost.org/LICENSE_1_0.txt)
0008 
0009 #ifndef BOOST_LOCKFREE_DETAIL_COPY_PAYLOAD_HPP_INCLUDED
0010 #define BOOST_LOCKFREE_DETAIL_COPY_PAYLOAD_HPP_INCLUDED
0011 
0012 #include <boost/mpl/if.hpp>
0013 #include <boost/type_traits/is_convertible.hpp>
0014 
0015 #if defined(_MSC_VER)
0016 #pragma warning(push)
0017 #pragma warning(disable: 4512) // assignment operator could not be generated
0018 #endif
0019 
0020 namespace boost    {
0021 namespace lockfree {
0022 namespace detail   {
0023 
0024 struct copy_convertible
0025 {
0026     template <typename T, typename U>
0027     static void copy(T & t, U & u)
0028     {
0029         u = t;
0030     }
0031 };
0032 
0033 struct copy_constructible_and_copyable
0034 {
0035     template <typename T, typename U>
0036     static void copy(T & t, U & u)
0037     {
0038         u = U(t);
0039     }
0040 };
0041 
0042 template <typename T, typename U>
0043 void copy_payload(T & t, U & u)
0044 {
0045     typedef typename boost::mpl::if_<typename boost::is_convertible<T, U>::type,
0046                                      copy_convertible,
0047                                      copy_constructible_and_copyable
0048                                     >::type copy_type;
0049     copy_type::copy(t, u);
0050 }
0051 
0052 template <typename T>
0053 struct consume_via_copy
0054 {
0055     consume_via_copy(T & out):
0056         out_(out)
0057     {}
0058 
0059     template <typename U>
0060     void operator()(U & element)
0061     {
0062         copy_payload(element, out_);
0063     }
0064 
0065     T & out_;
0066 };
0067 
0068 struct consume_noop
0069 {
0070     template <typename U>
0071     void operator()(const U &)
0072     {
0073     }
0074 };
0075 
0076 
0077 }}}
0078 
0079 #if defined(_MSC_VER)
0080 #pragma warning(pop)
0081 #endif
0082 
0083 #endif  /* BOOST_LOCKFREE_DETAIL_COPY_PAYLOAD_HPP_INCLUDED */