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