Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:52:45

0001 // Copyright (C) 2013 Vicente J. Botet Escriba
0002 //
0003 //  Distributed under the Boost Software License, Version 1.0. (See accompanying
0004 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0005 //
0006 // 2013/09 Vicente J. Botet Escriba
0007 //    Adapt to boost from CCIA C++11 implementation
0008 //    Make use of Boost.Move
0009 
0010 #ifndef BOOST_THREAD_DETAIL_FUNCTION_WRAPPER_HPP
0011 #define BOOST_THREAD_DETAIL_FUNCTION_WRAPPER_HPP
0012 
0013 #include <boost/config.hpp>
0014 #include <boost/thread/detail/memory.hpp>
0015 #include <boost/thread/detail/move.hpp>
0016 
0017 #include <boost/thread/csbl/memory/unique_ptr.hpp>
0018 
0019 #include <memory>
0020 #include <functional>
0021 
0022 namespace boost
0023 {
0024   namespace detail
0025   {
0026     class function_wrapper
0027     {
0028       struct impl_base
0029       {
0030         virtual void call()=0;
0031         virtual ~impl_base()
0032         {
0033         }
0034       };
0035       typedef boost::csbl::unique_ptr<impl_base> impl_base_type;
0036       impl_base_type impl;
0037       template <typename F>
0038       struct impl_type: impl_base
0039       {
0040         F f;
0041         impl_type(F const &f_)
0042           : f(f_)
0043         {}
0044         impl_type(BOOST_THREAD_RV_REF(F) f_)
0045           : f(boost::move(f_))
0046         {}
0047 
0048         void call()
0049         {
0050           if (impl) f();
0051         }
0052       };
0053     public:
0054       BOOST_THREAD_MOVABLE_ONLY(function_wrapper)
0055 
0056 //#if ! defined  BOOST_NO_CXX11_RVALUE_REFERENCES
0057       template<typename F>
0058       function_wrapper(F const& f):
0059       impl(new impl_type<F>(f))
0060       {}
0061 //#endif
0062       template<typename F>
0063       function_wrapper(BOOST_THREAD_RV_REF(F) f):
0064       impl(new impl_type<F>(boost::forward<F>(f)))
0065       {}
0066       function_wrapper(BOOST_THREAD_RV_REF(function_wrapper) other) BOOST_NOEXCEPT :
0067       impl(other.impl)
0068       {
0069         other.impl = 0;
0070       }
0071       function_wrapper()
0072         : impl(0)
0073       {
0074       }
0075       ~function_wrapper()
0076       {
0077       }
0078 
0079       function_wrapper& operator=(BOOST_THREAD_RV_REF(function_wrapper) other) BOOST_NOEXCEPT
0080       {
0081         impl=other.impl;
0082         other.impl=0;
0083         return *this;
0084       }
0085 
0086       void operator()()
0087       { impl->call();}
0088 
0089     };
0090   }
0091 }
0092 
0093 #endif // header