Mercurial > hg > vamp-build-and-test
annotate DEPENDENCIES/generic/include/boost/thread/detail/function_wrapper.hpp @ 125:34e428693f5d vext
Vext -> Repoint
author | Chris Cannam |
---|---|
date | Thu, 14 Jun 2018 11:15:39 +0100 |
parents | f46d142149f5 |
children |
rev | line source |
---|---|
Chris@102 | 1 // Copyright (C) 2013 Vicente J. Botet Escriba |
Chris@102 | 2 // |
Chris@102 | 3 // Distributed under the Boost Software License, Version 1.0. (See accompanying |
Chris@102 | 4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
Chris@102 | 5 // |
Chris@102 | 6 // 2013/09 Vicente J. Botet Escriba |
Chris@102 | 7 // Adapt to boost from CCIA C++11 implementation |
Chris@102 | 8 // Make use of Boost.Move |
Chris@102 | 9 |
Chris@102 | 10 #ifndef BOOST_THREAD_DETAIL_FUNCTION_WRAPPER_HPP |
Chris@102 | 11 #define BOOST_THREAD_DETAIL_FUNCTION_WRAPPER_HPP |
Chris@102 | 12 |
Chris@102 | 13 #include <boost/config.hpp> |
Chris@102 | 14 #include <boost/thread/detail/memory.hpp> |
Chris@102 | 15 #include <boost/thread/detail/move.hpp> |
Chris@102 | 16 |
Chris@102 | 17 #include <boost/thread/csbl/memory/unique_ptr.hpp> |
Chris@102 | 18 |
Chris@102 | 19 #include <memory> |
Chris@102 | 20 #include <functional> |
Chris@102 | 21 |
Chris@102 | 22 namespace boost |
Chris@102 | 23 { |
Chris@102 | 24 namespace detail |
Chris@102 | 25 { |
Chris@102 | 26 class function_wrapper |
Chris@102 | 27 { |
Chris@102 | 28 struct impl_base |
Chris@102 | 29 { |
Chris@102 | 30 virtual void call()=0; |
Chris@102 | 31 virtual ~impl_base() |
Chris@102 | 32 { |
Chris@102 | 33 } |
Chris@102 | 34 }; |
Chris@102 | 35 typedef boost::csbl::unique_ptr<impl_base> impl_base_type; |
Chris@102 | 36 impl_base_type impl; |
Chris@102 | 37 template <typename F> |
Chris@102 | 38 struct impl_type: impl_base |
Chris@102 | 39 { |
Chris@102 | 40 F f; |
Chris@102 | 41 impl_type(F const &f_) |
Chris@102 | 42 : f(f_) |
Chris@102 | 43 {} |
Chris@102 | 44 impl_type(BOOST_THREAD_RV_REF(F) f_) |
Chris@102 | 45 : f(boost::move(f_)) |
Chris@102 | 46 {} |
Chris@102 | 47 |
Chris@102 | 48 void call() |
Chris@102 | 49 { |
Chris@102 | 50 if (impl) f(); |
Chris@102 | 51 } |
Chris@102 | 52 }; |
Chris@102 | 53 public: |
Chris@102 | 54 BOOST_THREAD_MOVABLE_ONLY(function_wrapper) |
Chris@102 | 55 |
Chris@102 | 56 //#if ! defined BOOST_NO_CXX11_RVALUE_REFERENCES |
Chris@102 | 57 template<typename F> |
Chris@102 | 58 function_wrapper(F const& f): |
Chris@102 | 59 impl(new impl_type<F>(f)) |
Chris@102 | 60 {} |
Chris@102 | 61 //#endif |
Chris@102 | 62 template<typename F> |
Chris@102 | 63 function_wrapper(BOOST_THREAD_RV_REF(F) f): |
Chris@102 | 64 impl(new impl_type<F>(boost::forward<F>(f))) |
Chris@102 | 65 {} |
Chris@102 | 66 function_wrapper(BOOST_THREAD_RV_REF(function_wrapper) other) BOOST_NOEXCEPT : |
Chris@102 | 67 impl(other.impl) |
Chris@102 | 68 { |
Chris@102 | 69 other.impl = 0; |
Chris@102 | 70 } |
Chris@102 | 71 function_wrapper() |
Chris@102 | 72 : impl(0) |
Chris@102 | 73 { |
Chris@102 | 74 } |
Chris@102 | 75 ~function_wrapper() |
Chris@102 | 76 { |
Chris@102 | 77 } |
Chris@102 | 78 |
Chris@102 | 79 function_wrapper& operator=(BOOST_THREAD_RV_REF(function_wrapper) other) BOOST_NOEXCEPT |
Chris@102 | 80 { |
Chris@102 | 81 impl=other.impl; |
Chris@102 | 82 other.impl=0; |
Chris@102 | 83 return *this; |
Chris@102 | 84 } |
Chris@102 | 85 |
Chris@102 | 86 void operator()() |
Chris@102 | 87 { impl->call();} |
Chris@102 | 88 |
Chris@102 | 89 }; |
Chris@102 | 90 } |
Chris@102 | 91 } |
Chris@102 | 92 |
Chris@102 | 93 #endif // header |