apply.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. #include <boost/context/detail/invoke.hpp>
  14. #include <boost/context/detail/index_sequence.hpp>
  15. #ifdef BOOST_HAS_ABI_HEADERS
  16. # include BOOST_ABI_PREFIX
  17. #endif
  18. namespace boost {
  19. namespace context {
  20. namespace detail {
  21. template< typename Fn, typename Tpl, std::size_t ... I >
  22. auto
  23. apply_impl( Fn && fn, Tpl && tpl, index_sequence< I ... >)
  24. -> decltype( invoke( std::forward< Fn >( fn), std::get< I >( std::forward< Tpl >( tpl) ) ... ) )
  25. {
  26. return invoke( std::forward< Fn >( fn), std::get< I >( std::forward< Tpl >( tpl) ) ... );
  27. }
  28. template< typename Fn, typename Tpl >
  29. auto
  30. apply( Fn && fn, Tpl && tpl)
  31. -> decltype( apply_impl( std::forward< Fn >( fn),
  32. std::forward< Tpl >( tpl),
  33. make_index_sequence< std::tuple_size< typename std::decay< Tpl >::type >::value >{}) )
  34. {
  35. return apply_impl( std::forward< Fn >( fn),
  36. std::forward< Tpl >( tpl),
  37. make_index_sequence< std::tuple_size< typename std::decay< Tpl >::type >::value >{});
  38. }
  39. }}}
  40. #ifdef BOOST_HAS_ABI_HEADERS
  41. #include BOOST_ABI_SUFFIX
  42. #endif
  43. #endif // BOOST_CONTEXT_DETAIL_APPLY_H