invoke.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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_INVOKE_H
  6. #define BOOST_CONTEXT_DETAIL_INVOKE_H
  7. #include <functional>
  8. #include <type_traits>
  9. #include <utility>
  10. #include <boost/config.hpp>
  11. #include <boost/context/detail/config.hpp>
  12. #ifdef BOOST_HAS_ABI_HEADERS
  13. # include BOOST_ABI_PREFIX
  14. #endif
  15. namespace boost {
  16. namespace context {
  17. namespace detail {
  18. template< typename Fn, typename ... Args >
  19. typename std::enable_if<
  20. std::is_member_pointer< typename std::decay< Fn >::type >::value,
  21. typename std::result_of< Fn &&( Args && ... ) >::type
  22. >::type
  23. invoke( Fn && fn, Args && ... args) {
  24. return std::mem_fn( fn)( std::forward< Args >( args) ... );
  25. }
  26. template< typename Fn, typename ... Args >
  27. typename std::enable_if<
  28. ! std::is_member_pointer< typename std::decay< Fn >::type >::value,
  29. typename std::result_of< Fn &&( Args && ... ) >::type
  30. >::type
  31. invoke( Fn && fn, Args && ... args) {
  32. return std::forward< Fn >( fn)( std::forward< Args >( args) ... );
  33. }
  34. }}}
  35. #ifdef BOOST_HAS_ABI_HEADERS
  36. #include BOOST_ABI_SUFFIX
  37. #endif
  38. #endif // BOOST_CONTEXT_DETAIL_INVOKE_H