File indexing completed on 2025-01-18 09:30:34
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_COROUTINE2_DETAIL_WRAP_H
0008 #define BOOST_COROUTINE2_DETAIL_WRAP_H
0009
0010 #include <functional>
0011 #include <type_traits>
0012
0013 #include <boost/config.hpp>
0014 #if defined(BOOST_NO_CXX17_STD_INVOKE)
0015 #include <boost/context/detail/invoke.hpp>
0016 #endif
0017 #include <boost/context/fiber.hpp>
0018
0019 #include <boost/coroutine2/detail/config.hpp>
0020
0021 #ifdef BOOST_HAS_ABI_HEADERS
0022 # include BOOST_ABI_PREFIX
0023 #endif
0024
0025 namespace boost {
0026 namespace coroutines2 {
0027 namespace detail {
0028
0029 template< typename Fn1, typename Fn2 >
0030 class wrapper {
0031 private:
0032 typename std::decay< Fn1 >::type fn1_;
0033 typename std::decay< Fn2 >::type fn2_;
0034
0035 public:
0036 wrapper( Fn1 && fn1, Fn2 && fn2) :
0037 fn1_( std::move( fn1) ),
0038 fn2_( std::move( fn2) ) {
0039 }
0040
0041 wrapper( wrapper const&) = delete;
0042 wrapper & operator=( wrapper const&) = delete;
0043
0044 wrapper( wrapper && other) = default;
0045 wrapper & operator=( wrapper && other) = default;
0046
0047 boost::context::fiber
0048 operator()( boost::context::fiber && c) {
0049 #if defined(BOOST_NO_CXX17_STD_INVOKE)
0050 return boost::context::detail::invoke(
0051 std::move( fn1_),
0052 fn2_,
0053 std::forward< boost::context::fiber >( c) );
0054 #else
0055 return std::invoke(
0056 std::move( fn1_),
0057 fn2_,
0058 std::forward< boost::context::fiber >( c) );
0059 #endif
0060 }
0061 };
0062
0063 template< typename Fn1, typename Fn2 >
0064 wrapper< Fn1, Fn2 >
0065 wrap( Fn1 && fn1, Fn2 && fn2) {
0066 return wrapper< Fn1, Fn2 >(
0067 std::forward< Fn1 >( fn1),
0068 std::forward< Fn2 >( fn2) );
0069 }
0070
0071 }}}
0072
0073 #ifdef BOOST_HAS_ABI_HEADERS
0074 #include BOOST_ABI_SUFFIX
0075 #endif
0076
0077 #endif