fork(1) download
  1. // functional standard header
  2. #pragma once
  3. #ifndef _FUNCTIONAL_
  4. #define _FUNCTIONAL_
  5. #ifndef RC_INVOKED
  6. #include <xfunctional>
  7.  
  8. #pragma pack(push,_CRT_PACKING)
  9. #pragma warning(push,3)
  10. #pragma push_macro("new")
  11. #undef new
  12.  
  13. #include <exception>
  14. #include <typeinfo>
  15. #include <tuple> // for bind
  16.  
  17. #pragma warning(disable: 4100 4180 4244 4521 4522)
  18.  
  19. _STD_BEGIN
  20. // IMPLEMENT mem_fn
  21. // TEMPLATE FUNCTION mem_fn
  22. template<class _Rx,
  23. class _Arg0>
  24. _Call_wrapper<_Callable_pmd<_Rx _Arg0::*const, _Arg0> >
  25. mem_fn(_Rx _Arg0::*const _Pmd)
  26. { // return data object wrapper
  27. return (_Call_wrapper<_Callable_pmd<_Rx _Arg0::*const, _Arg0> >(_Pmd));
  28. }
  29.  
  30. // TEMPLATE CLASS _Mem_fn_wrap
  31. template<class _Rx,
  32. class _Pmf,
  33. class _Arg0, _MAX_CLASS_LIST>
  34. class _Mem_fn_wrap;
  35.  
  36. template<class _Rx,
  37. class _Pmf,
  38. class _Arg0>
  39. class _Mem_fn_wrap<_Rx, _Pmf, _Arg0>
  40. : public _Call_wrapper<_Callable_pmf<_Pmf, _Arg0> >,
  41. public _Fun_class_base<_Rx, _Arg0>
  42. { // wrap pointer to member function, one argument
  43. public:
  44. typedef _Rx result_type;
  45. typedef _Arg0 *argument_type;
  46.  
  47. _Mem_fn_wrap(_Pmf _Fx)
  48. : _Call_wrapper<_Callable_pmf<_Pmf, _Arg0> >(_Fx)
  49. { // construct
  50. }
  51. };
  52.  
  53. #define _CLASS_MEM_FN_WRAP( \
  54. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
  55. template<class _Rx, \
  56. class _Pmf, \
  57. class _Arg0, \
  58. class _Arg1 COMMA LIST(_CLASS_TYPE)> \
  59. class _Mem_fn_wrap<_Rx, _Pmf, _Arg0, _Arg1 COMMA LIST(_TYPE), \
  60. PADDING_LIST(_NIL_PAD)> \
  61. : public _Call_wrapper<_Callable_pmf<_Pmf, _Arg0> >, \
  62. public _Fun_class_base<_Rx, _Arg0, _Arg1 COMMA LIST(_TYPE)> \
  63. { /* wrap pointer to member function, two or more arguments */ \
  64. public: \
  65. typedef _Rx result_type; \
  66. typedef _Arg0 *first_argument_type; \
  67. typedef _Arg1 second_argument_type; \
  68. _Mem_fn_wrap(_Pmf _Fx) \
  69. : _Call_wrapper<_Callable_pmf<_Pmf, _Arg0> >(_Fx) \
  70. { /* construct */ \
  71. } \
  72. };
  73.  
  74. _VARIADIC_EXPAND_0X(_CLASS_MEM_FN_WRAP, , , , )
  75. #undef _CLASS_MEM_FN_WRAP
  76.  
  77. // TEMPLATE FUNCTION mem_fn, pointer to member function
  78. #define _MEM_FN_IMPL( \
  79. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, CALL_OPT, CV_OPT, X3, X4) \
  80. template<class _Rx, \
  81. class _Arg0 COMMA LIST(_CLASS_TYPE)> \
  82. _Mem_fn_wrap<_Rx, _Rx(_Arg0::*)(LIST(_TYPE)) CV_OPT CALL_OPT, \
  83. CV_OPT _Arg0 COMMA LIST(_TYPE)> \
  84. mem_fn(_Rx(_Arg0::*_Pm)(LIST(_TYPE)) CV_OPT CALL_OPT) \
  85. { /* bind to pointer to member function */ \
  86. return (_Mem_fn_wrap<_Rx, _Rx(_Arg0::*)(LIST(_TYPE)) CV_OPT CALL_OPT, \
  87. CV_OPT _Arg0 COMMA LIST(_TYPE)>(_Pm)); \
  88. }
  89.  
  90. #define _VARIADIC_MEM_FN_IMPL(FUNC, CALL_OPT) \
  91. _VARIADIC_EXPAND_0X(FUNC, CALL_OPT, , , ) \
  92. _VARIADIC_EXPAND_0X(FUNC, CALL_OPT, const, , ) \
  93. _VARIADIC_EXPAND_0X(FUNC, CALL_OPT, volatile, , ) \
  94. _VARIADIC_EXPAND_0X(FUNC, CALL_OPT, const volatile, , )
  95.  
  96. _VARIADIC_MEM_FN_IMPL(_MEM_FN_IMPL, )
  97.  
  98. #undef _VARIADIC_MEM_FN_IMPL
  99. #undef _MEM_FN_IMPL
  100.  
  101. // IMPLEMENT function
  102.  
  103. // CLASS bad_function_call
  104. class bad_function_call
  105. : public _XSTD exception
  106. { // null function pointer exception
  107. public:
  108. explicit bad_function_call(const char * = 0) _NOEXCEPT
  109. { // construct with ignored message
  110. }
  111.  
  112. virtual const char *__CLR_OR_THIS_CALL what() const _THROW0()
  113. { // return pointer to message string
  114. return ("bad function call");
  115. }
  116. };
  117.  
  118. _CRTIMP2_PURE _NO_RETURN(__CLRCALL_PURE_OR_CDECL _Xbad_function_call());
  119.  
  120. // TEMPLATE CLASS _Func_base
  121. template<class _Rx,
  122. _MAX_CLASS_LIST>
  123. class _Func_base;
  124.  
  125. #define _CLASS_FUNC_BASE( \
  126. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
  127. template<class _Rx COMMA LIST(_CLASS_TYPE)> \
  128. class _Func_base<_Rx COMMA LIST(_TYPE), PADDING_LIST(_NIL_PAD)> \
  129. { /* abstract base for implementation types */ \
  130. public: \
  131. typedef _Func_base<_Rx COMMA LIST(_TYPE)> _Myt; \
  132. virtual _Myt *_Copy(void *) = 0; \
  133. virtual _Myt *_Move(void *) = 0; \
  134. virtual _Rx _Do_call(LIST(_TYPE_REFREF)) = 0; \
  135. virtual const _XSTD2 type_info& _Target_type() const = 0; \
  136. virtual void _Delete_this(bool) = 0; \
  137. const void *_Target(const _XSTD2 type_info& _Info) const \
  138. { /* return pointer to stored object of type _Info */ \
  139. return (_Target_type() == _Info ? _Get() : 0); \
  140. } \
  141. virtual ~_Func_base() _NOEXCEPT \
  142. { /* destroy the object */ \
  143. } \
  144. private: \
  145. virtual const void *_Get() const = 0; \
  146. };
  147.  
  148. _VARIADIC_EXPAND_0X(_CLASS_FUNC_BASE, , , , )
  149. #undef _CLASS_FUNC_BASE
  150.  
  151. // TEMPLATE CLASS _Func_impl
  152. template<class _Callable,
  153. class _Alloc,
  154. class _Rx,
  155. _MAX_CLASS_LIST>
  156. class _Func_impl;
  157.  
  158. #define _CLASS_FUNC_IMPL( \
  159. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
  160. template<class _Callable, \
  161. class _Alloc, \
  162. class _Rx COMMA LIST(_CLASS_TYPE)> \
  163. class _Func_impl<_Callable, _Alloc, _Rx COMMA LIST(_TYPE), \
  164. PADDING_LIST(_NIL_PAD)> \
  165. : public _Func_base<_Rx COMMA LIST(_TYPE)> \
  166. { /* derived class for specific implementation types */ \
  167. public: \
  168. typedef _Func_impl<_Callable, _Alloc, _Rx COMMA LIST(_TYPE)> _Myt; \
  169. typedef _Func_base<_Rx COMMA LIST(_TYPE)> _Mybase; \
  170. typedef typename _Alloc::template rebind<_Func_impl>::other _Myalty; \
  171. _Func_impl(const _Func_impl& _Right) \
  172. : _Callee(_Right._Callee), \
  173. _Myal(_Right._Myal) \
  174. { /* copy construct */ \
  175. } \
  176. _Func_impl(_Func_impl& _Right) \
  177. : _Callee(_Right._Callee), \
  178. _Myal(_Right._Myal) \
  179. { /* copy construct */ \
  180. } \
  181. _Func_impl(_Func_impl&& _Right) \
  182. : _Callee(_STD forward<_Callable>(_Right._Callee)), \
  183. _Myal(_Right._Myal) \
  184. { /* move construct */ \
  185. } \
  186. _Func_impl(typename _Callable::_MyTy&& _Val, \
  187. const _Myalty& _Ax = _Myalty()) \
  188. : _Callee(_STD forward<typename _Callable::_MyTy>(_Val)), _Myal(_Ax) \
  189. { /* construct */ \
  190. } \
  191. template<class _Other> \
  192. _Func_impl(_Other&& _Val, \
  193. const _Myalty& _Ax = _Myalty()) \
  194. : _Callee(_STD forward<_Other>(_Val)), _Myal(_Ax) \
  195. { /* construct */ \
  196. } \
  197. virtual _Mybase *_Copy(void *_Where) \
  198. { /* return clone of *this */ \
  199. if (_Where == 0) \
  200. _Where = _Myal.allocate(1); \
  201. ::new (_Where) _Myt(_Callee); \
  202. return ((_Mybase *)_Where); \
  203. } \
  204. virtual _Mybase *_Move(void *_Where) \
  205. { /* return clone of *this */ \
  206. if (_Where == 0) \
  207. _Where = _Myal.allocate(1); \
  208. ::new (_Where) _Myt(_STD move(_Callee)); \
  209. return ((_Mybase *)_Where); \
  210. } \
  211. virtual ~_Func_impl() _NOEXCEPT \
  212. { /* destroy the object */ \
  213. } \
  214. virtual _Rx _Do_call(LIST(_TYPE_REFREF_ARG)) \
  215. { /* call wrapped function */ \
  216. return (_Callee.template _ApplyX<_Rx>( \
  217. LIST(_FORWARD_ARG))); \
  218. } \
  219. virtual const _XSTD2 type_info& _Target_type() const \
  220. { /* return type information for stored object */ \
  221. return (typeid(typename _Callable::_MyTy)); \
  222. } \
  223. private: \
  224. virtual const void *_Get() const \
  225. { /* return address of stored object */ \
  226. return (reinterpret_cast<const void*>(&_Callee._Get())); \
  227. } \
  228. virtual void _Delete_this(bool _Deallocate) \
  229. { /* destroy self */ \
  230. _Myalty _Al = _Myal; \
  231. _Al.destroy(this); \
  232. if (_Deallocate) \
  233. _Al.deallocate(this, 1); \
  234. } \
  235. _Callable _Callee; \
  236. _Myalty _Myal; \
  237. };
  238.  
  239. _VARIADIC_EXPAND_0X(_CLASS_FUNC_IMPL, , , , )
  240. #undef _CLASS_FUNC_IMPL
  241.  
  242. // TEMPLATE CLASS _Func_class
  243. template<class _Ret,
  244. _MAX_CLASS_LIST>
  245. class _Func_class;
  246.  
  247. #define _CLASS_FUNC_CLASS_BEGIN_0X( \
  248. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
  249. template<class _Ret COMMA LIST(_CLASS_TYPEX)> \
  250. class _Func_class<_Ret COMMA LIST(_TYPEX), PADDING_LIST(_NIL_PAD)> \
  251. : public _Fun_class_base<_Ret COMMA LIST(_TYPEX)> \
  252. { /* implement function template */ \
  253. public: \
  254. typedef _Func_class<_Ret COMMA LIST(_TYPEX)> _Myt; \
  255. typedef typename _Fun_class_base<_Ret COMMA LIST(_TYPEX)>::_Arg0 _Arg0; \
  256. typedef _Func_base<_Ret COMMA LIST(_TYPEX)> _Ptrt; \
  257. typedef _Ret result_type; \
  258. _Ret operator()(LIST(_TYPEX_ARG)) const \
  259. { /* call through stored object */ \
  260. if (_Impl == 0) \
  261. _Xbad_function_call(); \
  262. return (_Impl->_Do_call(LIST(_FORWARD_ARGX))); \
  263. } \
  264. bool _Empty() const \
  265. { /* return true if no stored object */ \
  266. return (_Impl == 0); \
  267. } \
  268. ~_Func_class() _NOEXCEPT \
  269. { /* destroy the object */ \
  270. _Tidy(); \
  271. } \
  272. protected: \
  273. void _Reset() \
  274. { /* remove stored object */ \
  275. _Set(0); \
  276. } \
  277. void _Reset(const _Myt& _Right) \
  278. { /* copy _Right's stored object */ \
  279. if (_Right._Impl == 0) \
  280. _Set(0); \
  281. else if (_Right._Local()) \
  282. _Set(_Right._Impl->_Copy((void *)&_Space)); \
  283. else \
  284. _Set(_Right._Impl->_Copy(0)); \
  285. } \
  286. void _Resetm(_Myt&& _Right) \
  287. { /* move _Right's stored object */ \
  288. if (_Right._Impl == 0) \
  289. _Set(0); \
  290. else if (_Right._Local()) \
  291. { /* move and tidy */ \
  292. _Set(_Right._Impl->_Move((void *)&_Space)); \
  293. _Right._Tidy(); \
  294. } \
  295. else \
  296. { /* steal from _Right */ \
  297. _Set(_Right._Impl); \
  298. _Right._Set(0); \
  299. } \
  300. } \
  301. template<class _Fty> \
  302. void _Reset(_Fty&& _Val) \
  303. { /* store copy of _Val */ \
  304. _Reset_alloc(_STD forward<_Fty>(_Val), allocator<_Myt>()); \
  305. } \
  306. template<class _Fty, \
  307. class _Alloc> \
  308. void _Reset_alloc(_Fty&& _Val, _Alloc _Ax) \
  309. { /* store copy of _Val with allocator */ \
  310. typedef _Callable_obj<typename decay<_Fty>::type> \
  311. _MyWrapper; \
  312. typedef _Func_impl<_MyWrapper, _Alloc, \
  313. _Ret COMMA LIST(_TYPEX)> _Myimpl; \
  314. _Do_alloc<_Myimpl>(_STD forward<_Fty>(_Val), _Ax); \
  315. }
  316.  
  317. // CALL_OPT = (__cdecl, VC++ variants)
  318. #define _CLASS_FUNC_CLASS_MIDDLE0_0X( \
  319. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, CALL_OPT, X2, X3, X4) \
  320. template<class _Fret COMMA LIST(_CLASS_TYPE)> \
  321. void _Reset(_Fret (CALL_OPT *const _Val)(LIST(_TYPE_ARG))) \
  322. { /* store copy of _Val */ \
  323. _Reset_alloc(_Val, allocator<_Myt>()); \
  324. } \
  325. template<class _Fret COMMA LIST(_CLASS_TYPE), \
  326. class _Alloc> \
  327. void _Reset_alloc(_Fret (CALL_OPT *const _Val)(LIST(_TYPE_ARG)), \
  328. _Alloc _Ax) \
  329. { /* store copy of _Val with allocator */ \
  330. typedef _Callable_fun<_Fret (CALL_OPT *const)(LIST(_TYPE))> \
  331. _MyWrapper; \
  332. typedef _Func_impl<_MyWrapper, _Alloc, _Ret COMMA LIST(_TYPEX)> \
  333. _Myimpl; \
  334. _Do_alloc<_Myimpl>(_Val, _Ax); \
  335. }
  336.  
  337. #define _CLASS_FUNC_CLASS_MIDDLE1_1( \
  338. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
  339. template<class _Fret, \
  340. class _Farg0> \
  341. void _Reset(_Fret _Farg0::*const _Val) \
  342. { /* store copy of _Val */ \
  343. _Reset_alloc(_Val, allocator<_Myt>()); \
  344. } \
  345. template<class _Fret, \
  346. class _Farg0, \
  347. class _Alloc> \
  348. void _Reset_alloc(_Fret _Farg0::*const _Val, _Alloc _Ax) \
  349. { /* store copy of _Val with allocator */ \
  350. typedef _Callable_pmd<_Fret _Farg0::*const, _Farg0> \
  351. _MyWrapper; \
  352. typedef _Func_impl<_MyWrapper, _Alloc, _Ret, _Arg0> \
  353. _Myimpl; \
  354. _Do_alloc<_Myimpl>(_Val, _Ax); \
  355. }
  356.  
  357. // CALL_OPT = (__thiscall, VC++ variants)
  358. // CV_OPT = {, const, volatile, const volatile}
  359. #define _CLASS_FUNC_CLASS_MIDDLE2_0X( \
  360. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, \
  361. CALL_OPT, CV_OPT, LIST_P1, COMMA_P1) \
  362. template<class _Fret, \
  363. class _Farg0 COMMA_P1 LIST_P1(_CLASS_TYPE)> \
  364. void _Reset(_Fret (CALL_OPT _Farg0::*const _Val)( \
  365. LIST_P1(_TYPE)) CV_OPT) \
  366. { /* store copy of _Val */ \
  367. _Reset_alloc(_Val, allocator<_Myt>()); \
  368. } \
  369. template<class _Fret, \
  370. class _Farg0 COMMA_P1 LIST_P1(_CLASS_TYPE), \
  371. class _Alloc> \
  372. void _Reset_alloc(_Fret (CALL_OPT _Farg0::*const _Val)( \
  373. LIST_P1(_TYPE)) CV_OPT, _Alloc _Ax) \
  374. { /* store copy of _Val */ \
  375. typedef _Callable_pmf< \
  376. _Fret (CALL_OPT _Farg0::*const)(LIST_P1(_TYPE)) CV_OPT, _Farg0> \
  377. _MyWrapper; \
  378. typedef _Func_impl<_MyWrapper, _Alloc, _Ret, \
  379. _Farg0 COMMA_P1 LIST_P1(_TYPE)> _Myimpl; \
  380. _Do_alloc<_Myimpl>(_Val, _Ax); \
  381. }
  382.  
  383. #define _CLASS_FUNC_CLASS_END_0X( \
  384. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
  385. void _Tidy() \
  386. { /* clean up */ \
  387. if (_Impl != 0) \
  388. { /* destroy callable object and maybe delete it */ \
  389. _Impl->_Delete_this(!_Local()); \
  390. _Impl = 0; \
  391. } \
  392. } \
  393. void _Swap(_Myt& _Right) \
  394. { /* swap contents with contents of _Right */ \
  395. if (this == &_Right) \
  396. ; /* same object, do nothing */ \
  397. else if (!_Local() && !_Right._Local()) \
  398. _STD swap(_Impl, _Right._Impl); /* just swap pointers */ \
  399. else \
  400. { /* do three-way copy */ \
  401. _Myt _Temp; \
  402. _Temp._Resetm(_STD forward<_Myt>(*this)); \
  403. _Tidy(); \
  404. _Resetm(_STD forward<_Myt>(_Right)); \
  405. _Right._Tidy(); \
  406. _Right._Resetm(_STD forward<_Myt>(_Temp)); \
  407. } \
  408. } \
  409. const _XSTD2 type_info& _Target_type() const \
  410. { /* return type information for stored object */ \
  411. return (_Impl ? _Impl->_Target_type() : typeid(void)); \
  412. } \
  413. const void *_Target(const _XSTD2 type_info& _Info) const \
  414. { /* return pointer to stored object */ \
  415. return (_Impl ? _Impl->_Target(_Info) : 0); \
  416. } \
  417. private: \
  418. template<class _Myimpl, \
  419. class _Fty, \
  420. class _Alloc> \
  421. void _Do_alloc(_Fty&& _Val, \
  422. _Alloc _Ax) \
  423. { /* store copy of _Val with allocator */ \
  424. void *_Vptr = 0; \
  425. _Myimpl *_Ptr = 0; \
  426. if (sizeof (_Myimpl) <= sizeof (_Space)) \
  427. { /* small enough, allocate locally */ \
  428. _Vptr = &_Space; \
  429. _Ptr = ::new (_Vptr) _Myimpl(_STD forward<_Fty>(_Val)); \
  430. } \
  431. else \
  432. { /* use allocator */ \
  433. typename _Alloc::template rebind<_Myimpl>::other _Al = _Ax; \
  434. _Vptr = _Al.allocate(1); \
  435. _Ptr = ::new (_Vptr) _Myimpl(_STD forward<_Fty>(_Val), _Al); \
  436. } \
  437. _Set(_Ptr); \
  438. } \
  439. void _Set(_Ptrt *_Ptr) \
  440. { /* store pointer to object */ \
  441. _Impl = _Ptr; \
  442. } \
  443. bool _Local() const \
  444. { /* test for locally stored copy of object */ \
  445. return ((void *)_Impl == (void *)&_Space); \
  446. } \
  447. typedef void (*_Pfnty)(); \
  448. union \
  449. { /* storage for small wrappers */ \
  450. _Pfnty _Pfn[3]; \
  451. void *_Pobj[3]; \
  452. long double _Ldbl; /* for maximum alignment */ \
  453. char _Alias[3 * sizeof (void *)]; /* to permit aliasing */ \
  454. } _Space; \
  455. _Ptrt *_Impl; \
  456. };
  457.  
  458. #define _CLASS_FUNC_CLASS_MIDDLE0_OPT_0X( \
  459. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
  460. _VARIADIC_CALL_OPT_X1(_CLASS_FUNC_CLASS_MIDDLE0_0X, \
  461. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, \
  462. __cdecl, , X3, X4)
  463.  
  464. #define _CLASS_FUNC_CLASS_MIDDLE2_OPT_0X( \
  465. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
  466. _VARIADIC_CALL_OPT_X2(_CLASS_FUNC_CLASS_MIDDLE2_0X, \
  467. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, \
  468. __thiscall, , X3, X4) \
  469. _VARIADIC_CALL_OPT_X2(_CLASS_FUNC_CLASS_MIDDLE2_0X, \
  470. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, \
  471. __thiscall, const, X3, X4) \
  472. _VARIADIC_CALL_OPT_X2(_CLASS_FUNC_CLASS_MIDDLE2_0X, \
  473. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, \
  474. __thiscall, volatile, X3, X4) \
  475. _VARIADIC_CALL_OPT_X2(_CLASS_FUNC_CLASS_MIDDLE2_0X, \
  476. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, \
  477. __thiscall, const volatile, X3, X4)
  478.  
  479. #define _CLASS_FUNC_CLASS_0( \
  480. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
  481. _CLASS_FUNC_CLASS_BEGIN_0X( \
  482. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
  483. _CLASS_FUNC_CLASS_MIDDLE0_OPT_0X( \
  484. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
  485. _CLASS_FUNC_CLASS_MIDDLE2_OPT_0X( \
  486. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
  487. _CLASS_FUNC_CLASS_END_0X( \
  488. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
  489.  
  490. #define _CLASS_FUNC_CLASS_1( \
  491. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
  492. _CLASS_FUNC_CLASS_BEGIN_0X( \
  493. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
  494. _CLASS_FUNC_CLASS_MIDDLE0_OPT_0X( \
  495. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
  496. _CLASS_FUNC_CLASS_MIDDLE1_1( \
  497. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
  498. _CLASS_FUNC_CLASS_MIDDLE2_OPT_0X( \
  499. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
  500. _CLASS_FUNC_CLASS_END_0X( \
  501. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4)
  502.  
  503. #define _CLASS_FUNC_CLASS_2X( \
  504. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
  505. _CLASS_FUNC_CLASS_BEGIN_0X( \
  506. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
  507. _CLASS_FUNC_CLASS_MIDDLE0_OPT_0X( \
  508. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
  509. _CLASS_FUNC_CLASS_MIDDLE2_OPT_0X( \
  510. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
  511. _CLASS_FUNC_CLASS_END_0X( \
  512. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4)
  513.  
  514. _VARIADIC_EXPAND_P1_0(_CLASS_FUNC_CLASS_0, , , , )
  515. _VARIADIC_EXPAND_P1_1(_CLASS_FUNC_CLASS_1, , , , )
  516. _VARIADIC_EXPAND_P1_2X(_CLASS_FUNC_CLASS_2X, , , , )
  517.  
  518. #undef _CLASS_FUNC_CLASS_BEGIN_0X
  519. #undef _CLASS_FUNC_CLASS_MIDDLE0_0X
  520. #undef _CLASS_FUNC_CLASS_MIDDLE1_1
  521. #undef _CLASS_FUNC_CLASS_MIDDLE2_0X
  522. #undef _CLASS_FUNC_CLASS_END_0X
  523. #undef _CLASS_FUNC_CLASS_MIDDLE0_OPT_0X
  524. #undef _CLASS_FUNC_CLASS_MIDDLE2_OPT_0X
  525.  
  526. #undef _CLASS_FUNC_CLASS_0
  527. #undef _CLASS_FUNC_CLASS_1
  528. #undef _CLASS_FUNC_CLASS_2X
  529.  
  530. // TEMPLATE CLASS _Get_function_impl
  531. template<class _Tx>
  532. struct _Get_function_impl;
  533.  
  534. #define _CLASS_GET_FUNCTION_IMPL( \
  535. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, CALL_OPT, X2, X3, X4) \
  536. template<class _Ret COMMA LIST(_CLASS_TYPE)> \
  537. struct _Get_function_impl<_Ret CALL_OPT (LIST(_TYPE))> \
  538. { /* determine type from argument list */ \
  539. typedef _Func_class<_Ret COMMA LIST(_TYPE)> type; \
  540. };
  541.  
  542. #define _CLASS_GET_FUNCTION_IMPL_CALLS( \
  543. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, CALL_OPT, X2, X3, X4) \
  544. _VARIADIC_CALL_OPT_X1(_CLASS_GET_FUNCTION_IMPL, \
  545. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, __cdecl, X2, X3, X4)
  546.  
  547. _VARIADIC_EXPAND_0X(_CLASS_GET_FUNCTION_IMPL_CALLS, , , , )
  548. #undef _CLASS_GET_FUNCTION_IMPL_CALLS
  549. #undef _CLASS_GET_FUNCTION_IMPL
  550.  
  551. // TEMPLATE CLASS function
  552. template<class _Fty>
  553. class function
  554. : public _Get_function_impl<_Fty>::type
  555. { // wrapper for callable objects
  556. public:
  557. typedef function<_Fty> _Myt;
  558. typedef typename _Get_function_impl<_Fty>::type _Mybase;
  559.  
  560. function() _NOEXCEPT
  561. { // construct empty function wrapper
  562. this->_Reset();
  563. }
  564.  
  565. function(nullptr_t) _NOEXCEPT
  566. { // construct empty function wrapper from null pointer
  567. this->_Reset();
  568. }
  569.  
  570. function(const _Myt& _Right)
  571. { // construct holding copy of _Right
  572. this->_Reset((const _Mybase&)_Right);
  573. }
  574.  
  575. function(_Myt& _Right)
  576. { // construct holding copy of _Right
  577. this->_Reset((const _Mybase&)_Right);
  578. }
  579.  
  580. function(const _Myt&& _Right)
  581. { // construct holding copy of _Right
  582. this->_Reset((const _Mybase&)_Right);
  583. }
  584.  
  585. template<class _Fx>
  586. function(const _Fx& _Func)
  587. { // construct wrapper holding copy of _Func
  588. this->_Reset(_Func);
  589. }
  590.  
  591. template<class _Fx,
  592. class _Alloc>
  593. function(_Fx _Func, const _Alloc& _Ax)
  594. { // construct wrapper holding copy of _Func, allocator (old style)
  595. this->_Reset_alloc(_Func, _Ax);
  596. }
  597.  
  598. template<class _Alloc>
  599. function(allocator_arg_t, const _Alloc&) _NOEXCEPT
  600. { // construct empty function wrapper, allocator
  601. this->_Reset();
  602. }
  603.  
  604. template<class _Alloc>
  605. function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT
  606. { // construct empty function wrapper from null pointer, allocator
  607. this->_Reset();
  608. }
  609.  
  610. template<class _Alloc>
  611. function(allocator_arg_t, const _Alloc& _Ax, const _Myt& _Right)
  612. { // construct wrapper holding copy of _Right, allocator
  613. this->_Reset_alloc((const _Mybase&)_Right, _Ax);
  614. }
  615.  
  616. template<class _Fx,
  617. class _Alloc>
  618. function(allocator_arg_t, const _Alloc& _Ax, _Fx _Func)
  619. { // construct wrapper holding copy of _Func, allocator (new style)
  620. this->_Reset_alloc(_Func, _Ax);
  621. }
  622.  
  623. template<class _Fx>
  624. function(reference_wrapper<_Fx> _Func)
  625. { // construct wrapper holding reference to _Func
  626. this->_Reset(_Func);
  627. }
  628.  
  629. template<class _Fx,
  630. class _Alloc>
  631. function(reference_wrapper<_Fx> _Func, const _Alloc& _Ax)
  632. { // construct wrapper holding reference to _Func
  633. this->_Reset_alloc(_Func, _Ax);
  634. }
  635.  
  636. ~function() _NOEXCEPT
  637. { // destroy the object
  638. this->_Tidy();
  639. }
  640.  
  641. _Myt& operator=(const _Myt& _Right)
  642. { // assign _Right
  643. if (this != &_Right)
  644. { // clean up and copy
  645. this->_Tidy();
  646. this->_Reset((const _Mybase&)_Right);
  647. }
  648. return (*this);
  649. }
  650.  
  651. _Myt& operator=(_Myt& _Right)
  652. { // assign _Right
  653. if (this != &_Right)
  654. { // clean up and copy
  655. this->_Tidy();
  656. this->_Reset((const _Mybase&)_Right);
  657. }
  658. return (*this);
  659. }
  660.  
  661. function(_Myt&& _Right)
  662. { // construct holding moved copy of _Right
  663. this->_Resetm(_STD forward<_Myt>(_Right));
  664. }
  665.  
  666. template<class _Alloc>
  667. function(allocator_arg_t, const _Alloc& _Al, _Myt&& _Right)
  668. { // construct wrapper holding moved copy of _Right, allocator
  669. this->_Resetm(_STD forward<_Myt>(_Right));
  670. }
  671.  
  672. template<class _Fx>
  673. function(_Fx&& _Func)
  674. { // construct wrapper holding moved _Func
  675. this->_Reset(_STD forward<_Fx>(_Func));
  676. }
  677.  
  678. _Myt& operator=(_Myt&& _Right)
  679. { // assign by moving _Right
  680. if (this != &_Right)
  681. { // clean up and copy
  682. this->_Tidy();
  683. this->_Resetm(_STD forward<_Myt>(_Right));
  684. }
  685. return (*this);
  686. }
  687.  
  688. template<class _Fx>
  689. _Myt& operator=(_Fx&& _Func)
  690. { // move function object _Func
  691. this->_Tidy();
  692. this->_Reset(_STD forward<_Fx>(_Func));
  693. return (*this);
  694. }
  695.  
  696. template<class _Fx,
  697. class _Alloc>
  698. void assign(_Fx&& _Func, const _Alloc& _Ax)
  699. { // construct wrapper holding copy of _Func
  700. this->_Tidy();
  701. this->_Reset_alloc(_STD forward<_Fx>(_Func), _Ax);
  702. }
  703.  
  704. function& operator=(nullptr_t)
  705. { // clear function object
  706. this->_Tidy();
  707. this->_Reset();
  708. return (*this);
  709. }
  710.  
  711. template<class _Fx>
  712. _Myt& operator=(reference_wrapper<_Fx> _Func) _NOEXCEPT
  713. { // assign wrapper holding reference to _Func
  714. this->_Tidy();
  715. this->_Reset(_Func);
  716. return (*this);
  717. }
  718.  
  719. template<class _Fx,
  720. class _Alloc>
  721. void assign(reference_wrapper<_Fx> _Func, const _Alloc& _Ax)
  722. { // construct wrapper holding reference to _Func
  723. this->_Tidy();
  724. this->_Reset_alloc(_Func, _Ax);
  725. }
  726.  
  727. void swap(_Myt& _Right) _NOEXCEPT
  728. { // swap with _Right
  729. this->_Swap(_Right);
  730. }
  731.  
  732. _TYPEDEF_BOOL_TYPE;
  733.  
  734. _OPERATOR_BOOL() const _NOEXCEPT
  735. { // test if wrapper holds null function pointer
  736. return (!this->_Empty() ? _CONVERTIBLE_TO_TRUE : 0);
  737. }
  738.  
  739. const _XSTD2 type_info& target_type() const _NOEXCEPT
  740. { // return type_info object for target type
  741. return (this->_Target_type());
  742. }
  743.  
  744. template<class _Fty2>
  745. _Fty2 *target() _NOEXCEPT
  746. { // return pointer to target object
  747. return ((_Fty2*)this->_Target(typeid(_Fty2)));
  748. }
  749.  
  750. template<class _Fty2>
  751. const _Fty2 *target() const _NOEXCEPT
  752. { // return pointer to target object
  753. return ((const _Fty2*)this->_Target(typeid(_Fty2)));
  754. }
  755.  
  756. private:
  757. template<class _Fty2>
  758. void operator==(const function<_Fty2>&); // not defined
  759. template<class _Fty2>
  760. void operator!=(const function<_Fty2>&); // not defined
  761. };
  762.  
  763. // TEMPLATE FUNCTION swap
  764. template<class _Fty>
  765. void swap(function<_Fty>& _Left, function<_Fty>& _Right)
  766. { // swap contents of _Left with contents of _Right
  767. _Left.swap(_Right);
  768. }
  769.  
  770. // TEMPLATE NULL POINTER COMPARISONS
  771. template<class _Fty>
  772. bool operator==(const function<_Fty>& _Other,
  773. nullptr_t) _NOEXCEPT
  774. { // compare to null pointer
  775. return (!_Other);
  776. }
  777.  
  778. template<class _Fty>
  779. bool operator==(nullptr_t _Npc,
  780. const function<_Fty>& _Other) _NOEXCEPT
  781. { // compare to null pointer
  782. return (operator==(_Other, _Npc));
  783. }
  784.  
  785. template<class _Fty>
  786. bool operator!=(const function<_Fty>& _Other,
  787. nullptr_t _Npc) _NOEXCEPT
  788. { // compare to null pointer
  789. return (!operator==(_Other, _Npc));
  790. }
  791.  
  792. template<class _Fty>
  793. bool operator!=(nullptr_t _Npc,
  794. const function<_Fty>& _Other) _NOEXCEPT
  795. { // compare to null pointer
  796. return (!operator==(_Other, _Npc));
  797. }
  798.  
  799. // IMPLEMENT bind
  800. // PLACEHOLDERS
  801. template<int _Nx>
  802. class _Ph
  803. { // placeholder
  804. };
  805.  
  806. template<class _Tx>
  807. struct is_placeholder
  808. : integral_constant<int, 0>
  809. { // template to indicate that _Tx is not a placeholder
  810. };
  811.  
  812. template<int _Nx>
  813. struct is_placeholder<_Ph<_Nx> >
  814. : integral_constant<int, _Nx>
  815. { // template specialization to indicate that _Ph<_Nx> is a placeholder
  816. };
  817.  
  818. // TEMPLATE CLASS is_bind_expression
  819. template<class _Tx>
  820. struct is_bind_expression
  821. : false_type
  822. { // template to indicate that _Tx is not a bind expression
  823. };
  824.  
  825. // TEMPLATE CLASS _Notforced
  826. struct _Notforced
  827. { // operator() returns result_of<...>::type
  828. };
  829.  
  830. template<bool _Forced,
  831. class _Ret,
  832. class _Fun,
  833. _MAX_CLASS_LIST>
  834. class _Bind;
  835.  
  836. // TEMPLATE CLASS is_bind_expression
  837. #define _CLASS_IS_BIND_EXPRESSION( \
  838. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, CV_OPT, X3, X4) \
  839. template<bool _Forced, \
  840. class _Ret, \
  841. class _Fun \
  842. COMMA LIST(_CLASS_TYPE)> \
  843. struct is_bind_expression<CV_OPT _Bind<_Forced, _Ret, _Fun, \
  844. LIST(_TYPE) COMMA PADDING_LIST(_NIL_PAD)> > \
  845. : true_type \
  846. { /* specialization to indicate a bind expression */ \
  847. };
  848.  
  849. _VARIADIC_EXPAND_0X(_CLASS_IS_BIND_EXPRESSION, , , , )
  850. _VARIADIC_EXPAND_0X(_CLASS_IS_BIND_EXPRESSION, , const, , )
  851. _VARIADIC_EXPAND_0X(_CLASS_IS_BIND_EXPRESSION, , volatile, , )
  852. _VARIADIC_EXPAND_0X(_CLASS_IS_BIND_EXPRESSION, , const volatile, , )
  853. #undef _CLASS_IS_BIND_EXPRESSION
  854.  
  855. // TEMPLATE CLASS _Is_reference_wrapper
  856. template<class _Barg>
  857. struct _Is_reference_wrapper
  858. : false_type
  859. { // false in general
  860. };
  861.  
  862. template<class _Barg>
  863. struct _Is_reference_wrapper<reference_wrapper<_Barg> >
  864. : true_type
  865. { // true if reference wrapper
  866. };
  867.  
  868. // TEMPLATE CLASS _Classify_barg
  869. enum _Barg_type
  870. { // classifications
  871. _Reference_wrapper,
  872. _Placeholder,
  873. _Bind_expression,
  874. _UDT
  875. };
  876.  
  877. template<class _Barg>
  878. struct _Classify_barg
  879. : integral_constant<_Barg_type,
  880. _Is_reference_wrapper<_Barg>::value ? _Reference_wrapper
  881. : 0 < is_placeholder<_Barg>::value ? _Placeholder
  882. : is_bind_expression<_Barg>::value ? _Bind_expression
  883. : _UDT>
  884. { // classifies expression
  885. };
  886.  
  887. // TEMPLATE CLASS _Fixarg_ret_base
  888. template<_Barg_type,
  889. class _Funx,
  890. class _Barg,
  891. class _Ftuple>
  892. struct _Fixarg_ret_base;
  893.  
  894. template<class _Funx,
  895. class _Barg,
  896. class _Ftuple>
  897. struct _Fixarg_ret_base<_Reference_wrapper, _Funx, _Barg, _Ftuple>
  898. { // return type for reference_wrapper
  899. typedef typename add_reference<typename _Barg::type>::type type;
  900. };
  901.  
  902. template<class _Funx,
  903. class _Barg,
  904. class _Ftuple>
  905. struct _Fixarg_ret_base<_Placeholder, _Funx, _Barg, _Ftuple>
  906. { // return type for placeholder
  907. typedef typename add_reference<
  908. typename tuple_element<is_placeholder<_Barg>::value - 1,
  909. _Ftuple>::type>::type type;
  910. };
  911.  
  912. // TEMPLATE CLASS _Call_ret
  913. template<class _Bind_t,
  914. class _Ftuple>
  915. struct _Call_ret;
  916.  
  917. #define _CALL_RET( \
  918. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
  919. template<class _Bind_t COMMA \
  920. LIST(_CLASS_TYPE)> \
  921. struct _Call_ret<_Bind_t, tuple<LIST(_TYPE)> > \
  922. { /* get return type for nested bind */ \
  923. typedef tuple<LIST(_TYPE)> _Ftuple; \
  924. typedef typename result_of<_Bind_t( \
  925. LIST(_TUPLE_ELEMENT_RTYPE))>::type type; \
  926. };
  927.  
  928. #define _TUPLE_ELEMENT_RTYPE(NUM) \
  929. typename tuple_element<NUM, _Ftuple>::_Rtype
  930.  
  931. _VARIADIC_EXPAND_0X(_CALL_RET, , , , )
  932. #undef _TUPLE_ELEMENT_RTYPE
  933. #undef _CALL_RET
  934.  
  935. template<class _Funx,
  936. class _Barg,
  937. class _Ftuple>
  938. struct _Fixarg_ret_base<_Bind_expression, _Funx, _Barg, _Ftuple>
  939. { // return type for nested bind
  940. typedef typename _Call_ret<_Barg, _Ftuple>::type type;
  941. };
  942.  
  943. template<class _Funx,
  944. class _Barg,
  945. class _Ftuple>
  946. struct _Fixarg_ret_base<_UDT, _Funx, _Barg, _Ftuple>
  947. { // return type for plain user-defined type
  948. typedef typename _Copy_cv<_Barg, _Funx>::type type;
  949. };
  950.  
  951. // TEMPLATE CLASS _Fixarg_ret
  952. template<class _Funx,
  953. class _Barg,
  954. class _Ftuple>
  955. struct _Fixarg_ret
  956. : _Fixarg_ret_base<
  957. _Classify_barg<typename remove_reference<_Barg>::type>::value,
  958. _Funx,
  959. typename remove_reference<_Barg>::type,
  960. _Ftuple>
  961. { // classifies arguments
  962. };
  963.  
  964. // TEMPLATE CLASS _Do_call_ret
  965. template<bool _Forced,
  966. class _Ret,
  967. class _Funx,
  968. class _Btuple,
  969. class _Ftuple>
  970. struct _Do_call_ret
  971. { // assume forced return type
  972. typedef _Ret type;
  973. };
  974.  
  975. #define _DO_CALL_RET( \
  976. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
  977. template<class _Ret, \
  978. class _Funx \
  979. COMMA LIST(_CLASS_TYPE), \
  980. class _Ftuple> \
  981. struct _Do_call_ret<false, _Ret, _Funx, tuple<LIST(_TYPE)>, _Ftuple> \
  982. { /* generate return type from simulated call */ \
  983. typedef tuple<LIST(_TYPE)> _Btuple; \
  984. template<class _Uty> \
  985. static auto _Fn(int) \
  986. -> decltype(declval<_Uty>()(LIST(_FIXARG_RET))); \
  987. template<class _Uty> \
  988. static auto _Fn(_Wrap_int) \
  989. -> void; \
  990. typedef decltype(_Fn<_Funx>(0)) type; \
  991. };
  992.  
  993. #define _FIXARG_RET(NUM) \
  994. declval<typename _Fixarg_ret<_Funx, typename tuple_element<NUM, _Btuple> \
  995. ::_Rtype, _Ftuple>::type>()
  996.  
  997. _VARIADIC_EXPAND_0X(_DO_CALL_RET, , , , )
  998. #undef _FIXARG_RET
  999. #undef _DO_CALL_RET
  1000.  
  1001. // TEMPLATE CLASS _Add_result_type
  1002. template<bool _Forced,
  1003. bool _Fun_has_result_type,
  1004. class _Ret,
  1005. class _Fun>
  1006. struct _Add_result_type
  1007. { // do not define result_type
  1008. };
  1009.  
  1010. template<bool _Fun_has_result_type,
  1011. class _Ret,
  1012. class _Fun>
  1013. struct _Add_result_type<true, _Fun_has_result_type, _Ret, _Fun>
  1014. { // define result_type as forced type
  1015. typedef _Ret result_type;
  1016. };
  1017.  
  1018. template<class _Ret,
  1019. class _Fun>
  1020. struct _Add_result_type<false, true, _Ret, _Fun>
  1021. { // define result type as nested in _Fun
  1022. typedef typename _Fun::result_type result_type;
  1023. };
  1024.  
  1025. // TEMPLATE FUNCTION _Fixarg
  1026. template<class _Funx,
  1027. class _Barg,
  1028. class _Btuple,
  1029. class _Ftuple> inline
  1030. typename enable_if<_Is_reference_wrapper<_Barg>::value,
  1031. typename _Fixarg_ret<_Funx, _Barg, _Ftuple>::type>::type
  1032. _Fixarg(_Funx&&, _Btuple& _Mybargs,
  1033. _Ftuple& _Myfargs,
  1034. _Barg& _Arg)
  1035. { // convert a reference_wrapper argument
  1036. return (_Arg.get());
  1037. }
  1038.  
  1039. template<class _Funx,
  1040. class _Barg,
  1041. class _Btuple,
  1042. class _Ftuple> inline
  1043. typename enable_if<0 < is_placeholder<_Barg>::value,
  1044. typename _Fixarg_ret<_Funx, _Barg, _Ftuple>::type>::type
  1045. _Fixarg(_Funx&&, _Btuple& _Mybargs,
  1046. _Ftuple& _Myfargs,
  1047. _Barg& _Arg)
  1048. { // convert a placeholder argument
  1049. const int _Nx = is_placeholder<_Barg>::value - 1;
  1050. return (get<_Nx>(_Myfargs));
  1051. }
  1052.  
  1053. #define _FIXARG_NESTED( \
  1054. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
  1055. template<class _Funx, \
  1056. class _Barg, \
  1057. class _Btuple \
  1058. COMMA LIST(_CLASS_TYPE)> inline \
  1059. typename enable_if<is_bind_expression<_Barg>::value, \
  1060. typename _Fixarg_ret<_Funx, \
  1061. typename _Copy_cv<_Barg, _Funx>::type, \
  1062. tuple<LIST(_TYPE)> >::type>::type \
  1063. _Fixarg(_Funx&&, _Btuple& _Mybargs, \
  1064. tuple<LIST(_TYPE)>& _Myfargs, \
  1065. _Barg& _Arg) \
  1066. { /* convert a nested _Bind argument */ \
  1067. return (_Arg(LIST(_BIND_ELEMENT_ARG))); \
  1068. }
  1069.  
  1070. #define _BIND_ELEMENT_ARG(NUM) \
  1071. _STD get<NUM>(_Myfargs)
  1072.  
  1073. _VARIADIC_EXPAND_0X(_FIXARG_NESTED, , , , )
  1074. #undef _BIND_ELEMENT_ARG
  1075. #undef _FIXARG_NESTED
  1076.  
  1077. template<class _Funx,
  1078. class _Barg,
  1079. class _Btuple,
  1080. class _Ftuple> inline
  1081. typename enable_if<!is_bind_expression<_Barg>::value
  1082. && !is_placeholder<_Barg>::value
  1083. && !_Is_reference_wrapper<_Barg>::value,
  1084. typename _Fixarg_ret<_Funx, _Barg, _Ftuple>::type>::type
  1085. _Fixarg(_Funx&&, _Btuple& _Mybargs,
  1086. _Ftuple& _Myfargs,
  1087. _Barg& _Arg)
  1088. { // convert a plain argument
  1089. return (_Arg);
  1090. }
  1091.  
  1092. // TEMPLATE CLASS _Bind
  1093. #define _CLASS_BIND( \
  1094. TEMPLATE_LIST2, PADDING_LIST2, LIST2, COMMA, X1, X2, X3, X4) \
  1095. template<bool _Forced, \
  1096. class _Ret, \
  1097. class _Fun COMMA LIST2(_CLASS_TYPEX)> \
  1098. class _Bind<_Forced, _Ret, _Fun, \
  1099. LIST2(_TYPEX) COMMA PADDING_LIST2(_NIL_PAD)> \
  1100. : public _Add_result_type<_Forced, \
  1101. _Has_result_type< \
  1102. typename decay<_Fun>::type>::type::value, \
  1103. _Ret, \
  1104. typename decay<_Fun>::type> \
  1105. { /* wrap bound function and arguments */ \
  1106. public: \
  1107. static const bool _Is_forced = _Forced; \
  1108. typedef _Ret _Retx; \
  1109. typedef typename decay<_Fun>::type _Funx; \
  1110. typedef tuple<LIST2(_DECAY_TYPEX)> _Bargs; \
  1111. template<class _Fun2 COMMA LIST2(_CLASS_TYPEX)> \
  1112. explicit _Bind(_Fun2&& _Fx COMMA LIST2(_TYPEX_REFREF_ARG)) \
  1113. : _Myfun(_STD forward<_Fun2>(_Fx)), \
  1114. _Mybargs(LIST2(_FORWARD_ARGX)) \
  1115. { /* construct fron functor and arguments */ \
  1116. } \
  1117. _Bind(const _Bind& _Right) \
  1118. : _Myfun(_Right._Myfun), \
  1119. _Mybargs(_Right._Mybargs) \
  1120. { /* construct by copying */ \
  1121. } \
  1122. _Bind(_Bind& _Right) \
  1123. : _Myfun(_Right._Myfun), \
  1124. _Mybargs(_Right._Mybargs) \
  1125. { /* construct by copying */ \
  1126. } \
  1127. _Bind(_Bind&& _Right) \
  1128. : _Myfun(_STD forward<_Funx>(_Right._Myfun)), \
  1129. _Mybargs(_STD forward<_Bargs>(_Right._Mybargs)) \
  1130. { /* construct by moving */ \
  1131. } \
  1132. _VARIADIC_EXPAND_ALT_0X(_CLASS_BIND_CALL_OP, (LIST2(_FIXARG)), , , ) \
  1133. private: \
  1134. _Funx _Myfun; /* the stored functor */ \
  1135. _Bargs _Mybargs; /* the bound arguments */ \
  1136. };
  1137.  
  1138. #define _CLASS_BIND_CALL_OP( \
  1139. TEMPLATE_LIST1, PADDING_LIST1, LIST1, COMMA1, LIST2_FIXARG, X2, X3, X4) \
  1140. TEMPLATE_LIST1(_CLASS_TYPE) \
  1141. typename _Do_call_ret<_Forced, _Ret, _Funx, _Bargs, \
  1142. tuple<LIST1(_TYPE_REF)> >::type \
  1143. operator()(LIST1(_TYPE_REFREF_ARG)) \
  1144. { /* evaluate the called function */ \
  1145. tuple<LIST1(_TYPE_REF)> _Myfargs = _STD tie(LIST1(_ARG)); \
  1146. return (_Myfun LIST2_FIXARG); \
  1147. }
  1148.  
  1149. #define _FIXARG(NUM) \
  1150. _Fixarg(_Myfun, _Mybargs, _Myfargs, _STD get<NUM>(_Mybargs))
  1151.  
  1152. _VARIADIC_EXPAND_0X(_CLASS_BIND, , , , )
  1153.  
  1154. #undef _CLASS_BIND_CALL_OP
  1155. #undef _FIXARG
  1156. #undef _CLASS_BIND
  1157.  
  1158. // TEMPLATE CLASS _Pmd_wrap
  1159. template<class _Pmd_t,
  1160. class _Rx,
  1161. class _Farg0>
  1162. struct _Pmd_wrap
  1163. { // wrap a pointer to member data
  1164. // typedef _Rx _Farg0::* _Pmd_t;
  1165.  
  1166. _Pmd_wrap(const _Pmd_t& _Pmd)
  1167. : _Mypmd(_Pmd)
  1168. { // construct with wrapped pointer
  1169. }
  1170.  
  1171. _Rx& operator()(_Farg0& _Fnobj) const
  1172. { // get the data
  1173. return (_Fnobj.*_Mypmd);
  1174. }
  1175.  
  1176. const _Rx& operator()(const _Farg0& _Fnobj) const
  1177. { // get the data
  1178. return (_Fnobj.*_Mypmd);
  1179. }
  1180.  
  1181. volatile _Rx& operator()(volatile _Farg0& _Fnobj) const
  1182. { // get the data
  1183. return (_Fnobj.*_Mypmd);
  1184. }
  1185.  
  1186. const volatile _Rx& operator()(const volatile _Farg0& _Fnobj) const
  1187. { // get the data
  1188. return (_Fnobj.*_Mypmd);
  1189. }
  1190.  
  1191. private:
  1192. _Pmd_t _Mypmd;
  1193. };
  1194.  
  1195. template<class _Pmf_t,
  1196. class _Rx,
  1197. class _Farg0,
  1198. _MAX_CLASS_LIST>
  1199. struct _Pmf_wrap;
  1200.  
  1201. #define _CLASS_RESULT_OF_PMD( \
  1202. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
  1203. template<class _Pmd_t, \
  1204. class _Rx, \
  1205. class _Farg0, \
  1206. class _Arg0 COMMA LIST(_CLASS_TYPE)> \
  1207. struct _Result_of<_Pmd_wrap<_Pmd_t, _Rx, _Farg0>, _Arg0, \
  1208. LIST(_TYPE) COMMA PADDING_LIST(_NIL_PAD)> \
  1209. { /* template to determine result of call operation */ \
  1210. typedef typename _Copy_cv<_Rx, _Arg0>::type type; \
  1211. }; \
  1212. template<class _Pmd_t, \
  1213. class _Rx, \
  1214. class _Farg0, \
  1215. class _Arg0 COMMA LIST(_CLASS_TYPE)> \
  1216. struct _Result_of<_Pmd_wrap<_Pmd_t, _Rx, _Farg0>, \
  1217. reference_wrapper<_Arg0>&, \
  1218. LIST(_TYPE) COMMA PADDING_LIST(_NIL_PAD), _Nil> \
  1219. { /* template to determine result of call operation */ \
  1220. typedef typename _Copy_cv<_Rx, _Arg0>::type type; \
  1221. };
  1222.  
  1223. _VARIADIC_EXPAND_0X(_CLASS_RESULT_OF_PMD, , , , )
  1224. #undef _CLASS_RESULT_OF_PMD
  1225.  
  1226. #define _CLASS_PMF_WRAP( \
  1227. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
  1228. template<class _Pmf_t, \
  1229. class _Rx, \
  1230. class _Farg0 COMMA LIST(_CLASS_TYPE)> \
  1231. struct _Pmf_wrap<_Pmf_t, _Rx, _Farg0, \
  1232. LIST(_TYPE) COMMA PADDING_LIST(_NIL_PAD)> \
  1233. { /* wrap a pointer to member function */ \
  1234. /* typedef _Rx (_Farg0::* _Pmf_t)(_Ftypes...); */ \
  1235. _Pmf_wrap(const _Pmf_t& _Pmf) \
  1236. : _Mypmf(_Pmf) \
  1237. { /* construct with wrapped pointer */ \
  1238. } \
  1239. _Rx operator()(_Farg0& _Fnobj COMMA LIST(_TYPE_ARG)) const \
  1240. { /* call the function */ \
  1241. return ((_Fnobj.*_Mypmf)(LIST(_FORWARD_ARG))); \
  1242. } \
  1243. _Rx operator()(const _Farg0& _Fnobj COMMA LIST(_TYPE_ARG)) const \
  1244. { /* call the function */ \
  1245. return ((_Fnobj.*_Mypmf)(LIST(_FORWARD_ARG))); \
  1246. } \
  1247. _Rx operator()(_Farg0 *_Pfnobj COMMA LIST(_TYPE_ARG)) const \
  1248. { /* call the function */ \
  1249. return ((_Pfnobj->*_Mypmf)(LIST(_FORWARD_ARG))); \
  1250. } \
  1251. _Rx operator()(const _Farg0 *_Pfnobj COMMA LIST(_TYPE_ARG)) const \
  1252. { /* call the function */ \
  1253. return ((_Pfnobj->*_Mypmf)(LIST(_FORWARD_ARG))); \
  1254. } \
  1255. template<class _Wrapper> \
  1256. _Rx operator()(_Wrapper& _Ptr COMMA LIST(_TYPE_ARG)) const \
  1257. { /* call the function */ \
  1258. return (((*_Ptr).*_Mypmf)(LIST(_FORWARD_ARG))); \
  1259. } \
  1260. template<class _Wrapper> \
  1261. _Rx operator()(const _Wrapper& _Ptr COMMA LIST(_TYPE_ARG)) const \
  1262. { /* call the function */ \
  1263. return (((*_Ptr).*_Mypmf)(LIST(_FORWARD_ARG))); \
  1264. } \
  1265. private: \
  1266. _Pmf_t _Mypmf; \
  1267. };
  1268.  
  1269. _VARIADIC_EXPAND_0X(_CLASS_PMF_WRAP, , , , )
  1270. #undef _CLASS_PMF_WRAP
  1271.  
  1272. // TEMPLATE FUNCTION bind (implicit return type)
  1273. #define _BIND_IMPLICIT0( \
  1274. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
  1275. template<class _Fun COMMA LIST(_CLASS_TYPE)> inline \
  1276. _Bind<false, void, _Fun COMMA LIST(_TYPE)> \
  1277. bind(_Fun&& _Fx COMMA LIST(_TYPE_REFREF_ARG)) \
  1278. { /* bind a function object */ \
  1279. return (_Bind<false, void, _Fun COMMA LIST(_TYPE)>( \
  1280. _STD forward<_Fun>(_Fx) COMMA LIST(_FORWARD_ARG))); \
  1281. }
  1282.  
  1283. _VARIADIC_EXPAND_0X(_BIND_IMPLICIT0, , , , )
  1284. #undef _BIND_IMPLICIT0
  1285.  
  1286. template<class _Rx,
  1287. class _Farg0,
  1288. class _Arg0> inline
  1289. _Bind<false, void, _Pmd_wrap<_Rx _Farg0::*, _Rx, _Farg0>, _Arg0>
  1290. bind(_Rx _Farg0::* const _Pmd, _Arg0&& _A0)
  1291. { // bind a wrapped member object pointer
  1292. return (_Bind<false, void,
  1293. _Pmd_wrap<_Rx _Farg0::*, _Rx, _Farg0>, _Arg0>(
  1294. _Pmd_wrap<_Rx _Farg0::*, _Rx, _Farg0>(_Pmd),
  1295. _STD forward<_Arg0>(_A0)));
  1296. }
  1297.  
  1298. #define _BIND_IMPLICIT1( \
  1299. TEMPLATE_LIST1, PADDING_LIST1, LIST1, COMMA1, \
  1300. TEMPLATE_LIST2, PADDING_LIST2, LIST2, COMMA2) \
  1301. template<class _Rx \
  1302. COMMA1 LIST1(_CLASS_TYPE) \
  1303. COMMA2 LIST2(_CLASS_TYPEX)> inline \
  1304. _Bind<true, _Rx, _Rx (* const)(LIST1(_TYPE)) COMMA2 LIST2(_TYPEX)> \
  1305. bind(_Rx (*_Pfx)(LIST1(_TYPE)) COMMA2 LIST2(_TYPEX_REFREF_ARG)) \
  1306. { /* bind a function pointer */ \
  1307. return (_Bind<true, _Rx, _Rx (* const)(LIST1(_TYPE)) \
  1308. COMMA2 LIST2(_TYPEX)>(_Pfx COMMA2 LIST2(_FORWARD_ARGX))); \
  1309. } \
  1310. template<class _Rx, \
  1311. class _Farg0 \
  1312. COMMA1 LIST1(_CLASS_TYPE) \
  1313. COMMA2 LIST2(_CLASS_TYPEX)> inline \
  1314. _Bind<true, _Rx, \
  1315. _Pmf_wrap<_Rx (_Farg0::*)(LIST1(_TYPE)), \
  1316. _Rx, _Farg0 COMMA1 LIST1(_TYPE)> \
  1317. COMMA2 LIST2(_TYPEX)> \
  1318. bind(_Rx (_Farg0::* const _Pmf)(LIST1(_TYPE)) \
  1319. COMMA2 LIST2(_TYPEX_REFREF_ARG)) \
  1320. { /* bind a wrapped member function pointer */ \
  1321. return (_Bind<true, _Rx, \
  1322. _Pmf_wrap<_Rx (_Farg0::*)(LIST1(_TYPE)), \
  1323. _Rx, _Farg0 COMMA1 LIST1(_TYPE)> \
  1324. COMMA2 LIST2(_TYPEX)>( \
  1325. _Pmf_wrap<_Rx (_Farg0::*)(LIST1(_TYPE)), \
  1326. _Rx, _Farg0 COMMA1 LIST1(_TYPE)>(_Pmf) \
  1327. COMMA2 LIST2(_FORWARD_ARGX))); \
  1328. } \
  1329. template<class _Rx, \
  1330. class _Farg0 \
  1331. COMMA1 LIST1(_CLASS_TYPE) \
  1332. COMMA2 LIST2(_CLASS_TYPEX)> inline \
  1333. _Bind<true, _Rx, \
  1334. _Pmf_wrap<_Rx (_Farg0::*)(LIST1(_TYPE)) const, \
  1335. _Rx, _Farg0 COMMA1 LIST1(_TYPE)> \
  1336. COMMA2 LIST2(_TYPEX)> \
  1337. bind(_Rx (_Farg0::* const _Pmf)(LIST1(_TYPE)) const \
  1338. COMMA2 LIST2(_TYPEX_REFREF_ARG)) \
  1339. { /* bind a wrapped member function pointer */ \
  1340. return (_Bind<true, _Rx, \
  1341. _Pmf_wrap<_Rx (_Farg0::*)(LIST1(_TYPE)) const, \
  1342. _Rx, _Farg0 COMMA1 LIST1(_TYPE)> \
  1343. COMMA2 LIST2(_TYPEX)>( \
  1344. _Pmf_wrap<_Rx (_Farg0::*)(LIST1(_TYPE)) const, \
  1345. _Rx, _Farg0 COMMA1 LIST1(_TYPE)>(_Pmf) \
  1346. COMMA2 LIST2(_FORWARD_ARGX))); \
  1347. } \
  1348. template<class _Rx, \
  1349. class _Farg0 \
  1350. COMMA1 LIST1(_CLASS_TYPE) \
  1351. COMMA2 LIST2(_CLASS_TYPEX)> inline \
  1352. _Bind<true, _Rx, \
  1353. _Pmf_wrap<_Rx (_Farg0::*)(LIST1(_TYPE)) volatile, \
  1354. _Rx, _Farg0 COMMA1 LIST1(_TYPE)> \
  1355. COMMA2 LIST2(_TYPEX)> \
  1356. bind(_Rx (_Farg0::* const _Pmf)(LIST1(_TYPE)) volatile \
  1357. COMMA2 LIST2(_TYPEX_REFREF_ARG)) \
  1358. { /* bind a wrapped member function pointer */ \
  1359. return (_Bind<true, _Rx, \
  1360. _Pmf_wrap<_Rx (_Farg0::*)(LIST1(_TYPE)) volatile, \
  1361. _Rx, _Farg0 COMMA1 LIST1(_TYPE)> \
  1362. COMMA2 LIST2(_TYPEX)>( \
  1363. _Pmf_wrap<_Rx (_Farg0::*)(LIST1(_TYPE)) volatile, \
  1364. _Rx, _Farg0 COMMA1 LIST1(_TYPE)>(_Pmf) \
  1365. COMMA2 LIST2(_FORWARD_ARGX))); \
  1366. } \
  1367. template<class _Rx, \
  1368. class _Farg0 \
  1369. COMMA1 LIST1(_CLASS_TYPE) \
  1370. COMMA2 LIST2(_CLASS_TYPEX)> inline \
  1371. _Bind<true, _Rx, \
  1372. _Pmf_wrap<_Rx (_Farg0::*)(LIST1(_TYPE)) const volatile, \
  1373. _Rx, _Farg0 COMMA1 LIST1(_TYPE)> \
  1374. COMMA2 LIST2(_TYPEX)> \
  1375. bind(_Rx (_Farg0::* const _Pmf)(LIST1(_TYPE)) const volatile \
  1376. COMMA2 LIST2(_TYPEX_REFREF_ARG)) \
  1377. { /* bind a wrapped member function pointer */ \
  1378. return (_Bind<true, _Rx, \
  1379. _Pmf_wrap<_Rx (_Farg0::*)(LIST1(_TYPE)) const volatile, \
  1380. _Rx, _Farg0 COMMA1 LIST1(_TYPE)> \
  1381. COMMA2 LIST2(_TYPEX)>( \
  1382. _Pmf_wrap<_Rx (_Farg0::*)(LIST1(_TYPE)) const volatile, \
  1383. _Rx, _Farg0 COMMA1 LIST1(_TYPE)>(_Pmf) \
  1384. COMMA2 LIST2(_FORWARD_ARGX))); \
  1385. }
  1386.  
  1387. _VARIADIC_EXPAND_0X_0X(_BIND_IMPLICIT1)
  1388. #undef _BIND_IMPLICIT1
  1389.  
  1390. // TEMPLATE FUNCTION bind (explicit return type)
  1391. #define _BIND_EXPLICIT0( \
  1392. TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
  1393. template<class _Ret, \
  1394. class _Fun COMMA LIST(_CLASS_TYPE)> inline \
  1395. _Bind<true, _Ret, _Fun COMMA LIST(_TYPE)> \
  1396. bind(_Fun&& _Fx COMMA LIST(_TYPE_REFREF_ARG)) \
  1397. { /* bind a function object */ \
  1398. return (_Bind<true, _Ret, _Fun COMMA LIST(_TYPE)>( \
  1399. _STD forward<_Fun>(_Fx) COMMA LIST(_FORWARD_ARG))); \
  1400. }
  1401. _VARIADIC_EXPAND_0X(_BIND_EXPLICIT0, , , , )
  1402. #undef _BIND_EXPLICIT0
  1403.  
  1404. template<class _Ret,
  1405. class _Rx,
  1406. class _Farg0,
  1407. class _Arg0> inline
  1408. typename enable_if<!is_same<_Ret, _Rx>::value,
  1409. _Bind<true, _Ret, _Pmd_wrap<_Rx _Farg0::*, _Rx, _Farg0>, _Arg0>
  1410. >::type
  1411. bind(_Rx _Farg0::* const _Pmd, _Arg0&& _A0)
  1412. { // bind a wrapped member object pointer
  1413. return (_Bind<true, _Ret,
  1414. _Pmd_wrap<_Rx _Farg0::*, _Rx, _Farg0>, _Arg0>(
  1415. _Pmd_wrap<_Rx _Farg0::*, _Rx, _Farg0>(_Pmd),
  1416. _STD forward<_Arg0>(_A0)));
  1417. }
  1418.  
  1419. #define _BIND_EXPLICIT1( \
  1420. TEMPLATE_LIST1, PADDING_LIST1, LIST1, COMMA1, \
  1421. TEMPLATE_LIST2, PADDING_LIST2, LIST2, COMMA2) \
  1422. template<class _Ret, \
  1423. class _Rx \
  1424. COMMA1 LIST1(_CLASS_TYPE) \
  1425. COMMA2 LIST2(_CLASS_TYPEX)> inline \
  1426. typename enable_if<!is_same<_Ret, _Rx>::value, \
  1427. _Bind<true, _Ret, _Rx (* const)(LIST1(_TYPE)) \
  1428. COMMA2 LIST2(_TYPEX)> >::type \
  1429. bind(_Rx (*_Pfx)(LIST1(_TYPE)) COMMA2 LIST2(_TYPEX_REFREF_ARG)) \
  1430. { /* bind a function pointer */ \
  1431. return (_Bind<true, _Ret, _Rx (* const)(LIST1(_TYPE)) \
  1432. COMMA2 LIST2(_TYPEX)>(_Pfx COMMA2 LIST2(_FORWARD_ARGX))); \
  1433. } \
  1434. template<class _Ret, \
  1435. class _Rx, \
  1436. class _Farg0 \
  1437. COMMA1 LIST1(_CLASS_TYPE) \
  1438. COMMA2 LIST2(_CLASS_TYPEX)> inline \
  1439. typename enable_if<!is_same<_Ret, _Rx>::value, \
  1440. _Bind<true, _Ret, \
  1441. _Pmf_wrap<_Rx (_Farg0::*)(LIST1(_TYPE)), \
  1442. _Rx, _Farg0 COMMA1 LIST1(_TYPE)> \
  1443. COMMA2 LIST2(_TYPEX)> >::type \
  1444. bind(_Rx (_Farg0::* const _Pmf)(LIST1(_TYPE)) \
  1445. COMMA2 LIST2(_TYPEX_REFREF_ARG)) \
  1446. { /* bind a wrapped member function pointer */ \
  1447. return (_Bind<true, _Ret, \
  1448. _Pmf_wrap<_Rx (_Farg0::*)(LIST1(_TYPE)), \
  1449. _Rx, _Farg0 COMMA1 LIST1(_TYPE)> \
  1450. COMMA2 LIST2(_TYPEX)>( \
  1451. _Pmf_wrap<_Rx (_Farg0::*)(LIST1(_TYPE)), \
  1452. _Rx, _Farg0 COMMA1 LIST1(_TYPE)>(_Pmf) \
  1453. COMMA2 LIST2(_FORWARD_ARGX))); \
  1454. } \
  1455. template<class _Ret, \
  1456. class _Rx, \
  1457. class _Farg0 \
  1458. COMMA1 LIST1(_CLASS_TYPE) \
  1459. COMMA2 LIST2(_CLASS_TYPEX)> inline \
  1460. typename enable_if<!is_same<_Ret, _Rx>::value, \
  1461. _Bind<true, _Ret, \
  1462. _Pmf_wrap<_Rx (_Farg0::*)(LIST1(_TYPE)) const, \
  1463. _Rx, _Farg0 COMMA1 LIST1(_TYPE)> \
  1464. COMMA2 LIST2(_TYPEX)> >::type \
  1465. bind(_Rx (_Farg0::* const _Pmf)(LIST1(_TYPE)) const \
  1466. COMMA2 LIST2(_TYPEX_REFREF_ARG)) \
  1467. { /* bind a wrapped member function pointer */ \
  1468. return (_Bind<true, _Ret, \
  1469. _Pmf_wrap<_Rx (_Farg0::*)(LIST1(_TYPE)) const, \
  1470. _Rx, _Farg0 COMMA1 LIST1(_TYPE)> \
  1471. COMMA2 LIST2(_TYPEX)>( \
  1472. _Pmf_wrap<_Rx (_Farg0::*)(LIST1(_TYPE)) const, \
  1473. _Rx, _Farg0 COMMA1 LIST1(_TYPE)>(_Pmf) \
  1474. COMMA2 LIST2(_FORWARD_ARGX))); \
  1475. } \
  1476. template<class _Ret, \
  1477. class _Rx, \
  1478. class _Farg0 \
  1479. COMMA1 LIST1(_CLASS_TYPE) \
  1480. COMMA2 LIST2(_CLASS_TYPEX)> inline \
  1481. typename enable_if<!is_same<_Ret, _Rx>::value, \
  1482. _Bind<true, _Ret, \
  1483. _Pmf_wrap<_Rx (_Farg0::*)(LIST1(_TYPE)) volatile, \
  1484. _Rx, _Farg0 COMMA1 LIST1(_TYPE)> \
  1485. COMMA2 LIST2(_TYPEX)> >::type \
  1486. bind(_Rx (_Farg0::* const _Pmf)(LIST1(_TYPE)) volatile \
  1487. COMMA2 LIST2(_TYPEX_REFREF_ARG)) \
  1488. { /* bind a wrapped member function pointer */ \
  1489. return (_Bind<true, _Ret, \
  1490. _Pmf_wrap<_Rx (_Farg0::*)(LIST1(_TYPE)) volatile, \
  1491. _Rx, _Farg0 COMMA1 LIST1(_TYPE)> \
  1492. COMMA2 LIST2(_TYPEX)>( \
  1493. _Pmf_wrap<_Rx (_Farg0::*)(LIST1(_TYPE)) volatile, \
  1494. _Rx, _Farg0 COMMA1 LIST1(_TYPE)>(_Pmf) \
  1495. COMMA2 LIST2(_FORWARD_ARGX))); \
  1496. } \
  1497. template<class _Ret, \
  1498. class _Rx, \
  1499. class _Farg0 \
  1500. COMMA1 LIST1(_CLASS_TYPE) \
  1501. COMMA2 LIST2(_CLASS_TYPEX)> inline \
  1502. typename enable_if<!is_same<_Ret, _Rx>::value, \
  1503. _Bind<true, _Ret, \
  1504. _Pmf_wrap<_Rx (_Farg0::*)(LIST1(_TYPE)) const volatile, \
  1505. _Rx, _Farg0 COMMA1 LIST1(_TYPE)> \
  1506. COMMA2 LIST2(_TYPEX)> >::type \
  1507. bind(_Rx (_Farg0::* const _Pmf)(LIST1(_TYPE)) const volatile \
  1508. COMMA2 LIST2(_TYPEX_REFREF_ARG)) \
  1509. { /* bind a wrapped member function pointer */ \
  1510. return (_Bind<true, _Ret, \
  1511. _Pmf_wrap<_Rx (_Farg0::*)(LIST1(_TYPE)) const volatile, \
  1512. _Rx, _Farg0 COMMA1 LIST1(_TYPE)> \
  1513. COMMA2 LIST2(_TYPEX)>( \
  1514. _Pmf_wrap<_Rx (_Farg0::*)(LIST1(_TYPE)) const volatile, \
  1515. _Rx, _Farg0 COMMA1 LIST1(_TYPE)>(_Pmf) \
  1516. COMMA2 LIST2(_FORWARD_ARGX))); \
  1517. }
  1518.  
  1519. _VARIADIC_EXPAND_0X_0X(_BIND_EXPLICIT1)
  1520. #undef _BIND_EXPLICIT1
  1521.  
  1522. // PLACEHOLDER ARGUMENTS
  1523. namespace placeholders { // placeholders
  1524. extern _CRTIMP2_PURE _Ph<1> _1;
  1525. extern _CRTIMP2_PURE _Ph<2> _2;
  1526. extern _CRTIMP2_PURE _Ph<3> _3;
  1527. extern _CRTIMP2_PURE _Ph<4> _4;
  1528. extern _CRTIMP2_PURE _Ph<5> _5;
  1529. extern _CRTIMP2_PURE _Ph<6> _6;
  1530. extern _CRTIMP2_PURE _Ph<7> _7;
  1531. extern _CRTIMP2_PURE _Ph<8> _8;
  1532. extern _CRTIMP2_PURE _Ph<9> _9;
  1533. extern _CRTIMP2_PURE _Ph<10> _10;
  1534. extern _CRTIMP2_PURE _Ph<11> _11;
  1535. extern _CRTIMP2_PURE _Ph<12> _12;
  1536. extern _CRTIMP2_PURE _Ph<13> _13;
  1537. extern _CRTIMP2_PURE _Ph<14> _14;
  1538. extern _CRTIMP2_PURE _Ph<15> _15;
  1539. extern _CRTIMP2_PURE _Ph<16> _16;
  1540. extern _CRTIMP2_PURE _Ph<17> _17;
  1541. extern _CRTIMP2_PURE _Ph<18> _18;
  1542. extern _CRTIMP2_PURE _Ph<19> _19;
  1543. extern _CRTIMP2_PURE _Ph<20> _20;
  1544. } // namespace placeholders
  1545.  
  1546. namespace tr1 { // TR1 additions
  1547. using _STD bad_function_call;
  1548. using _STD bind;
  1549. using _STD function;
  1550. using _STD is_bind_expression;
  1551. using _STD is_placeholder;
  1552. using _STD mem_fn;
  1553. using _STD swap;
  1554.  
  1555. namespace placeholders {
  1556. using namespace _STD placeholders;
  1557. } // namespace placeholders
  1558. } // namespace tr1
  1559. _STD_END
  1560.  
  1561. namespace std {
  1562. // TEMPLATE STRUCT uses_allocator
  1563. template<class _Fty,
  1564. class _Alloc>
  1565. struct uses_allocator<function<_Fty>, _Alloc>
  1566. : true_type
  1567. { // true_type if container allocator enabled
  1568. };
  1569. } // namespace std
  1570.  
  1571. #pragma pop_macro("new")
  1572. #pragma warning(pop)
  1573. #pragma pack(pop)
  1574. #endif /* RC_INVOKED */
  1575. #endif /* _FUNCTIONAL_ */
  1576.  
  1577. /*
  1578.  * Copyright (c) 1992-2012 by P.J. Plauger. ALL RIGHTS RESERVED.
  1579.  * Consult your license regarding permissions and restrictions.
  1580. V6.00:0009 */
  1581.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:2:9: warning: #pragma once in main file [enabled by default]
 #pragma once
         ^
prog.cpp:6:23: fatal error: xfunctional: No such file or directory
 #include <xfunctional>
                       ^
compilation terminated.
stdout
Standard output is empty