sgx_invoke 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // The LLVM Compiler Infrastructure
  5. //
  6. // This file is dual licensed under the MIT and the University of Illinois Open
  7. // Source Licenses. See LICENSE.TXT for details.
  8. //
  9. //===----------------------------------------------------------------------===//
  10. #ifndef _LIBCPP___SGX_INVOKE
  11. #define _LIBCPP___SGX_INVOKE
  12. // __invoke
  13. #if !defined(_LIBCPP_SGX_CONFIG)
  14. // bullets 1 and 2
  15. template <class _Fp, class _A0, class ..._Args,
  16. class = typename enable_if
  17. <
  18. is_member_function_pointer<typename remove_reference<_Fp>::type>::value &&
  19. is_base_of<typename remove_reference<typename __member_pointer_traits<typename remove_reference<_Fp>::type>::_ClassType>::type,
  20. typename remove_reference<_A0>::type>::value
  21. >::type
  22. >
  23. inline _LIBCPP_INLINE_VISIBILITY
  24. auto
  25. __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
  26. -> decltype((_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...))
  27. {
  28. return (_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...);
  29. }
  30. template <class _Fp, class _A0, class ..._Args,
  31. class = typename enable_if
  32. <
  33. is_member_function_pointer<typename remove_reference<_Fp>::type>::value &&
  34. !is_base_of<typename remove_reference<typename __member_pointer_traits<typename remove_reference<_Fp>::type>::_ClassType>::type,
  35. typename remove_reference<_A0>::type>::value
  36. >::type
  37. >
  38. inline _LIBCPP_INLINE_VISIBILITY
  39. auto
  40. __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
  41. -> decltype(((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...))
  42. {
  43. return ((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...);
  44. }
  45. // bullets 3 and 4
  46. template <class _Fp, class _A0,
  47. class = typename enable_if
  48. <
  49. is_member_object_pointer<typename remove_reference<_Fp>::type>::value &&
  50. is_base_of<typename __member_pointer_traits<typename remove_reference<_Fp>::type>::_ClassType,
  51. typename remove_reference<_A0>::type>::value
  52. >::type
  53. >
  54. inline _LIBCPP_INLINE_VISIBILITY
  55. auto
  56. __invoke(_Fp&& __f, _A0&& __a0)
  57. -> decltype(_VSTD::forward<_A0>(__a0).*__f)
  58. {
  59. return _VSTD::forward<_A0>(__a0).*__f;
  60. }
  61. template <class _Fp, class _A0,
  62. class = typename enable_if
  63. <
  64. is_member_object_pointer<typename remove_reference<_Fp>::type>::value &&
  65. !is_base_of<typename __member_pointer_traits<typename remove_reference<_Fp>::type>::_ClassType,
  66. typename remove_reference<_A0>::type>::value
  67. >::type
  68. >
  69. inline _LIBCPP_INLINE_VISIBILITY
  70. auto
  71. __invoke(_Fp&& __f, _A0&& __a0)
  72. -> decltype((*_VSTD::forward<_A0>(__a0)).*__f)
  73. {
  74. return (*_VSTD::forward<_A0>(__a0)).*__f;
  75. }
  76. // bullet 5
  77. template <class _Fp, class ..._Args>
  78. inline _LIBCPP_INLINE_VISIBILITY
  79. auto
  80. __invoke(_Fp&& __f, _Args&& ...__args)
  81. -> decltype(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...))
  82. {
  83. return _VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...);
  84. }
  85. #else //_LIBCPP_SGX_CONFIG
  86. struct __invoke_member_function_object_impl
  87. {
  88. template<class _Fp, class _A0, class... _Args>
  89. static inline _LIBCPP_INLINE_VISIBILITY
  90. auto
  91. __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
  92. -> decltype((_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...))
  93. {
  94. return (_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...);
  95. }
  96. };
  97. struct __invoke_member_function_pointer_impl
  98. {
  99. template<class _Fp, class _A0, class... _Args>
  100. static inline _LIBCPP_INLINE_VISIBILITY
  101. auto
  102. __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
  103. -> decltype(((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...))
  104. {
  105. return ((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...);
  106. }
  107. };
  108. struct __invoke_member_data_object_impl
  109. {
  110. template<class _Fp, class _A0>
  111. static inline _LIBCPP_INLINE_VISIBILITY
  112. auto
  113. __invoke(_Fp&& __f, _A0&& __a0)
  114. -> decltype(_VSTD::forward<_A0>(__a0).*__f)
  115. {
  116. return _VSTD::forward<_A0>(__a0).*__f;
  117. }
  118. };
  119. struct __invoke_member_data_pointer_impl
  120. {
  121. template<class _Fp, class _A0>
  122. static inline _LIBCPP_INLINE_VISIBILITY
  123. auto
  124. __invoke(_Fp&& __f, _A0&& __a0)
  125. -> decltype((*_VSTD::forward<_A0>(__a0)).*__f)
  126. {
  127. return (*_VSTD::forward<_A0>(__a0)).*__f;
  128. }
  129. };
  130. struct __invoke_function_other_impl
  131. {
  132. template <class _Fp, class ..._Args>
  133. static inline _LIBCPP_INLINE_VISIBILITY
  134. auto
  135. __invoke(_Fp&& __f, _Args&& ...__args)
  136. -> decltype(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...))
  137. {
  138. return _VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...);
  139. }
  140. };
  141. template<class _Fp, class _A0, class ..._Args>
  142. struct __invoke_member_function_pointer
  143. : conditional<is_base_of<typename remove_reference<typename __member_pointer_traits<typename remove_reference<_Fp>::type>::_ClassType>::type, typename remove_reference<_A0>::type>::value,
  144. __invoke_member_function_object_impl,
  145. __invoke_member_function_pointer_impl>::type {};
  146. template<class _Fp, class _A0>
  147. struct __invoke_member_object_pointer
  148. : conditional<is_base_of<typename __member_pointer_traits<typename remove_reference<_Fp>::type>::_ClassType, typename remove_reference<_A0>::type>::value,
  149. __invoke_member_data_object_impl,
  150. __invoke_member_data_pointer_impl>::type {};
  151. // bullets 1 and 2
  152. template<class _Fp, class _A0, class... _Args,
  153. class = typename enable_if<is_member_function_pointer<typename remove_reference<_Fp>::type>::value >::type>
  154. inline _LIBCPP_INLINE_VISIBILITY
  155. auto
  156. __invoke(_Fp&& __f, _A0&& __a0, _Args&&... __args)
  157. -> decltype(__invoke_member_function_pointer<_Fp, _A0, _Args...>::__invoke(_VSTD::forward<_Fp>(__f), _VSTD::forward<_A0>(__a0), _VSTD::forward<_Args>(__args)...))
  158. {
  159. return (__invoke_member_function_pointer<_Fp, _A0, _Args...>::__invoke(_VSTD::forward<_Fp>(__f), _VSTD::forward<_A0>(__a0), _VSTD::forward<_Args>(__args)...));
  160. }
  161. // bullets 3 and 4
  162. template<class _Fp, class _A0,
  163. class = typename enable_if <is_member_object_pointer<typename remove_reference<_Fp>::type>::value>::type>
  164. inline _LIBCPP_INLINE_VISIBILITY
  165. auto
  166. __invoke(_Fp&& __f, _A0&& __args)
  167. -> decltype(__invoke_member_object_pointer<_Fp, _A0>::__invoke(_VSTD::forward<_Fp>(__f), _VSTD::forward<_A0>(__args)))
  168. {
  169. return (__invoke_member_object_pointer<_Fp, _A0>::__invoke(_VSTD::forward<_Fp>(__f), _VSTD::forward<_A0>(__args)));
  170. }
  171. // bullet 5
  172. template<class _Fp, class... _Args>
  173. inline _LIBCPP_INLINE_VISIBILITY
  174. auto
  175. __invoke(_Fp&& __f, _Args&&... __args)
  176. -> decltype(__invoke_function_other_impl::__invoke(_VSTD::forward<_Fp>(__f), _VSTD::forward<_Args>(__args)...))
  177. {
  178. return (__invoke_function_other_impl::__invoke(_VSTD::forward<_Fp>(__f), _VSTD::forward<_Args>(__args)...));
  179. }
  180. #endif // _LIBCPP_SGX_CONFIG
  181. #endif // _LIBCPP___SGX_INVOKE