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