| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | #ifndef _GLIBCXX_INVOKE_H |
| 31 | #define _GLIBCXX_INVOKE_H 1 |
| 32 | |
| 33 | #pragma GCC system_header |
| 34 | |
| 35 | #if __cplusplus < 201103L |
| 36 | # include <bits/c++0x_warning.h> |
| 37 | #else |
| 38 | |
| 39 | #include <type_traits> |
| 40 | |
| 41 | namespace std _GLIBCXX_VISIBILITY(default) |
| 42 | { |
| 43 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | template<typename _Tp, typename _Up = typename __inv_unwrap<_Tp>::type> |
| 53 | constexpr _Up&& |
| 54 | __invfwd(typename remove_reference<_Tp>::type& __t) noexcept |
| 55 | { return static_cast<_Up&&>(__t); } |
| 56 | |
| 57 | template<typename _Res, typename _Fn, typename... _Args> |
| 58 | constexpr _Res |
| 59 | __invoke_impl(__invoke_other, _Fn&& __f, _Args&&... __args) |
| 60 | { return std::forward<_Fn>(__f)(std::forward<_Args>(__args)...); } |
| 61 | |
| 62 | template<typename _Res, typename _MemFun, typename _Tp, typename... _Args> |
| 63 | constexpr _Res |
| 64 | __invoke_impl(__invoke_memfun_ref, _MemFun&& __f, _Tp&& __t, |
| 65 | _Args&&... __args) |
| 66 | { return (__invfwd<_Tp>(__t).*__f)(std::forward<_Args>(__args)...); } |
| 67 | |
| 68 | template<typename _Res, typename _MemFun, typename _Tp, typename... _Args> |
| 69 | constexpr _Res |
| 70 | __invoke_impl(__invoke_memfun_deref, _MemFun&& __f, _Tp&& __t, |
| 71 | _Args&&... __args) |
| 72 | { |
| 73 | return ((*std::forward<_Tp>(__t)).*__f)(std::forward<_Args>(__args)...); |
| 74 | } |
| 75 | |
| 76 | template<typename _Res, typename _MemPtr, typename _Tp> |
| 77 | constexpr _Res |
| 78 | __invoke_impl(__invoke_memobj_ref, _MemPtr&& __f, _Tp&& __t) |
| 79 | { return __invfwd<_Tp>(__t).*__f; } |
| 80 | |
| 81 | template<typename _Res, typename _MemPtr, typename _Tp> |
| 82 | constexpr _Res |
| 83 | __invoke_impl(__invoke_memobj_deref, _MemPtr&& __f, _Tp&& __t) |
| 84 | { return (*std::forward<_Tp>(__t)).*__f; } |
| 85 | |
| 86 | |
| 87 | template<typename _Callable, typename... _Args> |
| 88 | constexpr typename __invoke_result<_Callable, _Args...>::type |
| 89 | __invoke(_Callable&& __fn, _Args&&... __args) |
| 90 | noexcept(__is_nothrow_invocable<_Callable, _Args...>::value) |
| 91 | { |
| 92 | using __result = __invoke_result<_Callable, _Args...>; |
| 93 | using __type = typename __result::type; |
| 94 | using __tag = typename __result::__invoke_type; |
| 95 | return std::__invoke_impl<__type>(__tag{}, std::forward<_Callable>(__fn), |
| 96 | std::forward<_Args>(__args)...); |
| 97 | } |
| 98 | |
| 99 | _GLIBCXX_END_NAMESPACE_VERSION |
| 100 | } |
| 101 | |
| 102 | #endif |
| 103 | |
| 104 | #endif |
| 105 | |