invoke.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #if _MSC_VER > 1800
  19. using std::invoke;
  20. #else
  21. template< typename Fn, typename ... Args >
  22. typename std::enable_if<
  23. std::is_member_pointer< typename std::decay< Fn >::type >::value,
  24. typename std::result_of< Fn &&( Args && ... ) >::type
  25. >::type
  26. invoke( Fn && fn, Args && ... args) {
  27. return std::mem_fn( fn)( std::forward< Args >( args) ... );
  28. }
  29. template< typename Fn, typename ... Args >
  30. typename std::enable_if<
  31. ! std::is_member_pointer< typename std::decay< Fn >::type >::value,
  32. typename std::result_of< Fn &&( Args && ... ) >::type
  33. >::type
  34. invoke( Fn && fn, Args && ... args) {
  35. return std::forward< Fn >( fn)( std::forward< Args >( args) ... );
  36. }
  37. #endif
  38. }}}
  39. #ifdef BOOST_HAS_ABI_HEADERS
  40. #include BOOST_ABI_SUFFIX
  41. #endif
  42. #endif // BOOST_CONTEXT_DETAIL_INVOKE_H