File indexing completed on 2025-01-18 09:52:45
0001
0002
0003
0004
0005
0006
0007
0008
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
0057 template<typename F>
0058 function_wrapper(F const& f):
0059 impl(new impl_type<F>(f))
0060 {}
0061
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