2
0
mirror of https://github.com/boostorg/fiber.git synced 2026-02-15 13:02:29 +00:00

add invoke() in orderr to support calling member fn

This commit is contained in:
Oliver Kowalke
2015-06-23 17:56:33 +02:00
parent dd374f3be4
commit 8a7d376450
2 changed files with 50 additions and 1 deletions

View File

@@ -0,0 +1,48 @@
// Copyright Oliver Kowalke 2014.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_FIBERS_DETAIL_INVOKE_H
#define BOOST_FIBERS_DETAIL_INVOKE_H
#include <functional>
#include <type_traits>
#include <utility>
#include <boost/config.hpp>
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_PREFIX
#endif
namespace boost {
namespace fibers {
namespace detail {
template< typename Fn, typename... Args >
typename std::enable_if<
std::is_member_pointer< typename std::decay< Fn >::type >::value,
typename std::result_of< Fn&&( Args && ...) >::type
>::type
invoke( Fn && fn, Args && ... args) {
return std::mem_fn( fn)( std::forward< Args >( args) ...);
}
template< typename Fn, typename ... Args >
typename std::enable_if<
! std::is_member_pointer< typename std::decay< Fn >::type >::value,
typename std::result_of< Fn&&( Args && ...) >::type
>::type
invoke( Fn && fn, Args && ... args) {
return std::forward< Fn >( fn)( std::forward< Args >( args) ...);
}
}}}
#ifdef BOOST_HAS_ABI_HEADERS
#include BOOST_ABI_SUFFIX
#endif
#endif // BOOST_FIBERS_DETAIL_INVOKE_H

View File

@@ -24,6 +24,7 @@
#include <boost/fiber/detail/config.hpp>
#include <boost/fiber/detail/fss.hpp>
#include <boost/fiber/detail/invoke.hpp>
#include <boost/fiber/detail/spinlock.hpp>
#include <boost/fiber/detail/scheduler.hpp>
#include <boost/fiber/fiber_manager.hpp>
@@ -122,7 +123,7 @@ private:
[=,fn=std::forward< Fn >( fn_),tpl=std::forward< Tpl >( tpl_)] () mutable {
try {
BOOST_ASSERT( is_running() );
fn(
detail::invoke( fn,
// std::tuple_element<> does not perfect forwarding
std::forward< decltype( std::get< I >( std::declval< Tpl >() ) ) >(
std::get< I >( std::forward< Tpl >( tpl) ) ) ... );