1
2 // Copyright Oliver Kowalke 2014.
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6
7 #ifndef BOOST_COROUTINE2_DETAIL_WRAP_H
8 #define BOOST_COROUTINE2_DETAIL_WRAP_H
9
10 #include <type_traits>
11
12 #include <boost/config.hpp>
13 #include <boost/context/detail/invoke.hpp>
14 #include <boost/context/fiber.hpp>
15
16 #include <boost/coroutine2/detail/config.hpp>
17
18 #ifdef BOOST_HAS_ABI_HEADERS
19 # include BOOST_ABI_PREFIX
20 #endif
21
22 namespace boost {
23 namespace coroutines2 {
24 namespace detail {
25
26 template< typename Fn1, typename Fn2 >
27 class wrapper {
28 private:
29 typename std::decay< Fn1 >::type fn1_;
30 typename std::decay< Fn2 >::type fn2_;
31
32 public:
wrapper(Fn1 && fn1,Fn2 && fn2)33 wrapper( Fn1 && fn1, Fn2 && fn2) :
34 fn1_( std::move( fn1) ),
35 fn2_( std::move( fn2) ) {
36 }
37
38 wrapper( wrapper const&) = delete;
39 wrapper & operator=( wrapper const&) = delete;
40
41 wrapper( wrapper && other) = default;
42 wrapper & operator=( wrapper && other) = default;
43
44 boost::context::fiber
operator ()(boost::context::fiber && c)45 operator()( boost::context::fiber && c) {
46 return boost::context::detail::invoke(
47 std::move( fn1_),
48 fn2_,
49 std::forward< boost::context::fiber >( c) );
50 }
51 };
52
53 template< typename Fn1, typename Fn2 >
54 wrapper< Fn1, Fn2 >
wrap(Fn1 && fn1,Fn2 && fn2)55 wrap( Fn1 && fn1, Fn2 && fn2) {
56 return wrapper< Fn1, Fn2 >(
57 std::forward< Fn1 >( fn1),
58 std::forward< Fn2 >( fn2) );
59 }
60
61 }}}
62
63 #ifdef BOOST_HAS_ABI_HEADERS
64 #include BOOST_ABI_SUFFIX
65 #endif
66
67 #endif // BOOST_COROUTINE2_DETAIL_WRAP_H
68