wrap.hpp 1.6 KB

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