apply.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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_CONTEXT_DETAIL_APPLY_H
  6. #define BOOST_CONTEXT_DETAIL_APPLY_H
  7. #include <functional>
  8. #include <tuple>
  9. #include <type_traits>
  10. #include <utility>
  11. #include <boost/config.hpp>
  12. #include <boost/context/detail/config.hpp>
  13. #if defined(BOOST_NO_CXX17_STD_INVOKE)
  14. #include <boost/context/detail/invoke.hpp>
  15. #endif
  16. #include <boost/context/detail/index_sequence.hpp>
  17. #ifdef BOOST_HAS_ABI_HEADERS
  18. # include BOOST_ABI_PREFIX
  19. #endif
  20. #if defined(BOOST_MSVC)
  21. # pragma warning(push)
  22. # pragma warning(disable: 4100)
  23. #endif
  24. namespace boost {
  25. namespace context {
  26. namespace detail {
  27. template< typename Fn, typename Tpl, std::size_t ... I >
  28. auto
  29. apply_impl( Fn && fn, Tpl && tpl, index_sequence< I ... >)
  30. #if defined(BOOST_NO_CXX17_STD_INVOKE)
  31. -> decltype( boost::context::detail::invoke( std::forward< Fn >( fn), std::get< I >( std::forward< Tpl >( tpl) ) ... ) )
  32. #else
  33. -> decltype( std::invoke( std::forward< Fn >( fn), std::get< I >( std::forward< Tpl >( tpl) ) ... ) )
  34. #endif
  35. {
  36. #if defined(BOOST_NO_CXX17_STD_INVOKE)
  37. return boost::context::detail::invoke( std::forward< Fn >( fn), std::get< I >( std::forward< Tpl >( tpl) ) ... );
  38. #else
  39. return std::invoke( std::forward< Fn >( fn), std::get< I >( std::forward< Tpl >( tpl) ) ... );
  40. #endif
  41. }
  42. template< typename Fn, typename Tpl >
  43. auto
  44. apply( Fn && fn, Tpl && tpl)
  45. -> decltype( apply_impl( std::forward< Fn >( fn),
  46. std::forward< Tpl >( tpl),
  47. make_index_sequence< std::tuple_size< typename std::decay< Tpl >::type >::value >{}) )
  48. {
  49. return apply_impl( std::forward< Fn >( fn),
  50. std::forward< Tpl >( tpl),
  51. make_index_sequence< std::tuple_size< typename std::decay< Tpl >::type >::value >{});
  52. }
  53. }}}
  54. #if defined(BOOST_MSVC)
  55. # pragma warning(pop)
  56. #endif
  57. #ifdef BOOST_HAS_ABI_HEADERS
  58. #include BOOST_ABI_SUFFIX
  59. #endif
  60. #endif // BOOST_CONTEXT_DETAIL_APPLY_H