function_template.hpp 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186
  1. // Boost.Function library
  2. // Copyright Douglas Gregor 2001-2006
  3. // Copyright Emil Dotchevski 2007
  4. // Use, modification and distribution is subject to the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. // For more information, see http://www.boost.org
  8. // Note: this header is a header template and must NOT have multiple-inclusion
  9. // protection.
  10. #include <boost/function/detail/prologue.hpp>
  11. #include <boost/core/no_exceptions_support.hpp>
  12. #if defined(BOOST_MSVC)
  13. # pragma warning( push )
  14. # pragma warning( disable : 4127 ) // "conditional expression is constant"
  15. #endif
  16. #define BOOST_FUNCTION_TEMPLATE_PARMS BOOST_PP_ENUM_PARAMS(BOOST_FUNCTION_NUM_ARGS, typename T)
  17. #define BOOST_FUNCTION_TEMPLATE_ARGS BOOST_PP_ENUM_PARAMS(BOOST_FUNCTION_NUM_ARGS, T)
  18. #define BOOST_FUNCTION_PARM(J,I,D) BOOST_PP_CAT(T,I) BOOST_PP_CAT(a,I)
  19. #define BOOST_FUNCTION_PARMS BOOST_PP_ENUM(BOOST_FUNCTION_NUM_ARGS,BOOST_FUNCTION_PARM,BOOST_PP_EMPTY)
  20. #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
  21. # define BOOST_FUNCTION_ARGS BOOST_PP_ENUM_PARAMS(BOOST_FUNCTION_NUM_ARGS, a)
  22. #else
  23. # define BOOST_FUNCTION_ARG(J,I,D) static_cast<BOOST_PP_CAT(T,I)&&>(BOOST_PP_CAT(a,I))
  24. # define BOOST_FUNCTION_ARGS BOOST_PP_ENUM(BOOST_FUNCTION_NUM_ARGS,BOOST_FUNCTION_ARG,BOOST_PP_EMPTY)
  25. #endif
  26. #define BOOST_FUNCTION_ARG_TYPE(J,I,D) \
  27. typedef BOOST_PP_CAT(T,I) BOOST_PP_CAT(BOOST_PP_CAT(arg, BOOST_PP_INC(I)),_type);
  28. #define BOOST_FUNCTION_ARG_TYPES BOOST_PP_REPEAT(BOOST_FUNCTION_NUM_ARGS,BOOST_FUNCTION_ARG_TYPE,BOOST_PP_EMPTY)
  29. // Comma if nonzero number of arguments
  30. #if BOOST_FUNCTION_NUM_ARGS == 0
  31. # define BOOST_FUNCTION_COMMA
  32. #else
  33. # define BOOST_FUNCTION_COMMA ,
  34. #endif // BOOST_FUNCTION_NUM_ARGS > 0
  35. // Class names used in this version of the code
  36. #define BOOST_FUNCTION_FUNCTION BOOST_JOIN(function,BOOST_FUNCTION_NUM_ARGS)
  37. #define BOOST_FUNCTION_FUNCTION_INVOKER \
  38. BOOST_JOIN(function_invoker,BOOST_FUNCTION_NUM_ARGS)
  39. #define BOOST_FUNCTION_VOID_FUNCTION_INVOKER \
  40. BOOST_JOIN(void_function_invoker,BOOST_FUNCTION_NUM_ARGS)
  41. #define BOOST_FUNCTION_FUNCTION_OBJ_INVOKER \
  42. BOOST_JOIN(function_obj_invoker,BOOST_FUNCTION_NUM_ARGS)
  43. #define BOOST_FUNCTION_VOID_FUNCTION_OBJ_INVOKER \
  44. BOOST_JOIN(void_function_obj_invoker,BOOST_FUNCTION_NUM_ARGS)
  45. #define BOOST_FUNCTION_FUNCTION_REF_INVOKER \
  46. BOOST_JOIN(function_ref_invoker,BOOST_FUNCTION_NUM_ARGS)
  47. #define BOOST_FUNCTION_VOID_FUNCTION_REF_INVOKER \
  48. BOOST_JOIN(void_function_ref_invoker,BOOST_FUNCTION_NUM_ARGS)
  49. #define BOOST_FUNCTION_MEMBER_INVOKER \
  50. BOOST_JOIN(function_mem_invoker,BOOST_FUNCTION_NUM_ARGS)
  51. #define BOOST_FUNCTION_VOID_MEMBER_INVOKER \
  52. BOOST_JOIN(function_void_mem_invoker,BOOST_FUNCTION_NUM_ARGS)
  53. #define BOOST_FUNCTION_GET_FUNCTION_INVOKER \
  54. BOOST_JOIN(get_function_invoker,BOOST_FUNCTION_NUM_ARGS)
  55. #define BOOST_FUNCTION_GET_FUNCTION_OBJ_INVOKER \
  56. BOOST_JOIN(get_function_obj_invoker,BOOST_FUNCTION_NUM_ARGS)
  57. #define BOOST_FUNCTION_GET_FUNCTION_REF_INVOKER \
  58. BOOST_JOIN(get_function_ref_invoker,BOOST_FUNCTION_NUM_ARGS)
  59. #define BOOST_FUNCTION_GET_MEMBER_INVOKER \
  60. BOOST_JOIN(get_member_invoker,BOOST_FUNCTION_NUM_ARGS)
  61. #define BOOST_FUNCTION_GET_INVOKER \
  62. BOOST_JOIN(get_invoker,BOOST_FUNCTION_NUM_ARGS)
  63. #define BOOST_FUNCTION_VTABLE BOOST_JOIN(basic_vtable,BOOST_FUNCTION_NUM_ARGS)
  64. #ifndef BOOST_NO_VOID_RETURNS
  65. # define BOOST_FUNCTION_VOID_RETURN_TYPE void
  66. # define BOOST_FUNCTION_RETURN(X) X
  67. #else
  68. # define BOOST_FUNCTION_VOID_RETURN_TYPE boost::detail::function::unusable
  69. # define BOOST_FUNCTION_RETURN(X) X; return BOOST_FUNCTION_VOID_RETURN_TYPE ()
  70. #endif
  71. namespace boost {
  72. namespace detail {
  73. namespace function {
  74. template<
  75. typename FunctionPtr,
  76. typename R BOOST_FUNCTION_COMMA
  77. BOOST_FUNCTION_TEMPLATE_PARMS
  78. >
  79. struct BOOST_FUNCTION_FUNCTION_INVOKER
  80. {
  81. static R invoke(function_buffer& function_ptr BOOST_FUNCTION_COMMA
  82. BOOST_FUNCTION_PARMS)
  83. {
  84. FunctionPtr f = reinterpret_cast<FunctionPtr>(function_ptr.members.func_ptr);
  85. return f(BOOST_FUNCTION_ARGS);
  86. }
  87. };
  88. template<
  89. typename FunctionPtr,
  90. typename R BOOST_FUNCTION_COMMA
  91. BOOST_FUNCTION_TEMPLATE_PARMS
  92. >
  93. struct BOOST_FUNCTION_VOID_FUNCTION_INVOKER
  94. {
  95. static BOOST_FUNCTION_VOID_RETURN_TYPE
  96. invoke(function_buffer& function_ptr BOOST_FUNCTION_COMMA
  97. BOOST_FUNCTION_PARMS)
  98. {
  99. FunctionPtr f = reinterpret_cast<FunctionPtr>(function_ptr.members.func_ptr);
  100. BOOST_FUNCTION_RETURN(f(BOOST_FUNCTION_ARGS));
  101. }
  102. };
  103. template<
  104. typename FunctionObj,
  105. typename R BOOST_FUNCTION_COMMA
  106. BOOST_FUNCTION_TEMPLATE_PARMS
  107. >
  108. struct BOOST_FUNCTION_FUNCTION_OBJ_INVOKER
  109. {
  110. static R invoke(function_buffer& function_obj_ptr BOOST_FUNCTION_COMMA
  111. BOOST_FUNCTION_PARMS)
  112. {
  113. FunctionObj* f;
  114. if (function_allows_small_object_optimization<FunctionObj>::value)
  115. f = reinterpret_cast<FunctionObj*>(function_obj_ptr.data);
  116. else
  117. f = reinterpret_cast<FunctionObj*>(function_obj_ptr.members.obj_ptr);
  118. return (*f)(BOOST_FUNCTION_ARGS);
  119. }
  120. };
  121. template<
  122. typename FunctionObj,
  123. typename R BOOST_FUNCTION_COMMA
  124. BOOST_FUNCTION_TEMPLATE_PARMS
  125. >
  126. struct BOOST_FUNCTION_VOID_FUNCTION_OBJ_INVOKER
  127. {
  128. static BOOST_FUNCTION_VOID_RETURN_TYPE
  129. invoke(function_buffer& function_obj_ptr BOOST_FUNCTION_COMMA
  130. BOOST_FUNCTION_PARMS)
  131. {
  132. FunctionObj* f;
  133. if (function_allows_small_object_optimization<FunctionObj>::value)
  134. f = reinterpret_cast<FunctionObj*>(function_obj_ptr.data);
  135. else
  136. f = reinterpret_cast<FunctionObj*>(function_obj_ptr.members.obj_ptr);
  137. BOOST_FUNCTION_RETURN((*f)(BOOST_FUNCTION_ARGS));
  138. }
  139. };
  140. template<
  141. typename FunctionObj,
  142. typename R BOOST_FUNCTION_COMMA
  143. BOOST_FUNCTION_TEMPLATE_PARMS
  144. >
  145. struct BOOST_FUNCTION_FUNCTION_REF_INVOKER
  146. {
  147. static R invoke(function_buffer& function_obj_ptr BOOST_FUNCTION_COMMA
  148. BOOST_FUNCTION_PARMS)
  149. {
  150. FunctionObj* f =
  151. reinterpret_cast<FunctionObj*>(function_obj_ptr.members.obj_ptr);
  152. return (*f)(BOOST_FUNCTION_ARGS);
  153. }
  154. };
  155. template<
  156. typename FunctionObj,
  157. typename R BOOST_FUNCTION_COMMA
  158. BOOST_FUNCTION_TEMPLATE_PARMS
  159. >
  160. struct BOOST_FUNCTION_VOID_FUNCTION_REF_INVOKER
  161. {
  162. static BOOST_FUNCTION_VOID_RETURN_TYPE
  163. invoke(function_buffer& function_obj_ptr BOOST_FUNCTION_COMMA
  164. BOOST_FUNCTION_PARMS)
  165. {
  166. FunctionObj* f =
  167. reinterpret_cast<FunctionObj*>(function_obj_ptr.members.obj_ptr);
  168. BOOST_FUNCTION_RETURN((*f)(BOOST_FUNCTION_ARGS));
  169. }
  170. };
  171. #if BOOST_FUNCTION_NUM_ARGS > 0
  172. /* Handle invocation of member pointers. */
  173. template<
  174. typename MemberPtr,
  175. typename R BOOST_FUNCTION_COMMA
  176. BOOST_FUNCTION_TEMPLATE_PARMS
  177. >
  178. struct BOOST_FUNCTION_MEMBER_INVOKER
  179. {
  180. static R invoke(function_buffer& function_obj_ptr BOOST_FUNCTION_COMMA
  181. BOOST_FUNCTION_PARMS)
  182. {
  183. MemberPtr* f =
  184. reinterpret_cast<MemberPtr*>(function_obj_ptr.data);
  185. return boost::mem_fn(*f)(BOOST_FUNCTION_ARGS);
  186. }
  187. };
  188. template<
  189. typename MemberPtr,
  190. typename R BOOST_FUNCTION_COMMA
  191. BOOST_FUNCTION_TEMPLATE_PARMS
  192. >
  193. struct BOOST_FUNCTION_VOID_MEMBER_INVOKER
  194. {
  195. static BOOST_FUNCTION_VOID_RETURN_TYPE
  196. invoke(function_buffer& function_obj_ptr BOOST_FUNCTION_COMMA
  197. BOOST_FUNCTION_PARMS)
  198. {
  199. MemberPtr* f =
  200. reinterpret_cast<MemberPtr*>(function_obj_ptr.data);
  201. BOOST_FUNCTION_RETURN(boost::mem_fn(*f)(BOOST_FUNCTION_ARGS));
  202. }
  203. };
  204. #endif
  205. template<
  206. typename FunctionPtr,
  207. typename R BOOST_FUNCTION_COMMA
  208. BOOST_FUNCTION_TEMPLATE_PARMS
  209. >
  210. struct BOOST_FUNCTION_GET_FUNCTION_INVOKER
  211. {
  212. typedef typename conditional<(is_void<R>::value),
  213. BOOST_FUNCTION_VOID_FUNCTION_INVOKER<
  214. FunctionPtr,
  215. R BOOST_FUNCTION_COMMA
  216. BOOST_FUNCTION_TEMPLATE_ARGS
  217. >,
  218. BOOST_FUNCTION_FUNCTION_INVOKER<
  219. FunctionPtr,
  220. R BOOST_FUNCTION_COMMA
  221. BOOST_FUNCTION_TEMPLATE_ARGS
  222. >
  223. >::type type;
  224. };
  225. template<
  226. typename FunctionObj,
  227. typename R BOOST_FUNCTION_COMMA
  228. BOOST_FUNCTION_TEMPLATE_PARMS
  229. >
  230. struct BOOST_FUNCTION_GET_FUNCTION_OBJ_INVOKER
  231. {
  232. typedef typename conditional<(is_void<R>::value),
  233. BOOST_FUNCTION_VOID_FUNCTION_OBJ_INVOKER<
  234. FunctionObj,
  235. R BOOST_FUNCTION_COMMA
  236. BOOST_FUNCTION_TEMPLATE_ARGS
  237. >,
  238. BOOST_FUNCTION_FUNCTION_OBJ_INVOKER<
  239. FunctionObj,
  240. R BOOST_FUNCTION_COMMA
  241. BOOST_FUNCTION_TEMPLATE_ARGS
  242. >
  243. >::type type;
  244. };
  245. template<
  246. typename FunctionObj,
  247. typename R BOOST_FUNCTION_COMMA
  248. BOOST_FUNCTION_TEMPLATE_PARMS
  249. >
  250. struct BOOST_FUNCTION_GET_FUNCTION_REF_INVOKER
  251. {
  252. typedef typename conditional<(is_void<R>::value),
  253. BOOST_FUNCTION_VOID_FUNCTION_REF_INVOKER<
  254. FunctionObj,
  255. R BOOST_FUNCTION_COMMA
  256. BOOST_FUNCTION_TEMPLATE_ARGS
  257. >,
  258. BOOST_FUNCTION_FUNCTION_REF_INVOKER<
  259. FunctionObj,
  260. R BOOST_FUNCTION_COMMA
  261. BOOST_FUNCTION_TEMPLATE_ARGS
  262. >
  263. >::type type;
  264. };
  265. #if BOOST_FUNCTION_NUM_ARGS > 0
  266. /* Retrieve the appropriate invoker for a member pointer. */
  267. template<
  268. typename MemberPtr,
  269. typename R BOOST_FUNCTION_COMMA
  270. BOOST_FUNCTION_TEMPLATE_PARMS
  271. >
  272. struct BOOST_FUNCTION_GET_MEMBER_INVOKER
  273. {
  274. typedef typename conditional<(is_void<R>::value),
  275. BOOST_FUNCTION_VOID_MEMBER_INVOKER<
  276. MemberPtr,
  277. R BOOST_FUNCTION_COMMA
  278. BOOST_FUNCTION_TEMPLATE_ARGS
  279. >,
  280. BOOST_FUNCTION_MEMBER_INVOKER<
  281. MemberPtr,
  282. R BOOST_FUNCTION_COMMA
  283. BOOST_FUNCTION_TEMPLATE_ARGS
  284. >
  285. >::type type;
  286. };
  287. #endif
  288. /* Given the tag returned by get_function_tag, retrieve the
  289. actual invoker that will be used for the given function
  290. object.
  291. Each specialization contains an "apply" nested class template
  292. that accepts the function object, return type, function
  293. argument types, and allocator. The resulting "apply" class
  294. contains two typedefs, "invoker_type" and "manager_type",
  295. which correspond to the invoker and manager types. */
  296. template<typename Tag>
  297. struct BOOST_FUNCTION_GET_INVOKER { };
  298. /* Retrieve the invoker for a function pointer. */
  299. template<>
  300. struct BOOST_FUNCTION_GET_INVOKER<function_ptr_tag>
  301. {
  302. template<typename FunctionPtr,
  303. typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS>
  304. struct apply
  305. {
  306. typedef typename BOOST_FUNCTION_GET_FUNCTION_INVOKER<
  307. FunctionPtr,
  308. R BOOST_FUNCTION_COMMA
  309. BOOST_FUNCTION_TEMPLATE_ARGS
  310. >::type
  311. invoker_type;
  312. typedef functor_manager<FunctionPtr> manager_type;
  313. };
  314. template<typename FunctionPtr, typename Allocator,
  315. typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS>
  316. struct apply_a
  317. {
  318. typedef typename BOOST_FUNCTION_GET_FUNCTION_INVOKER<
  319. FunctionPtr,
  320. R BOOST_FUNCTION_COMMA
  321. BOOST_FUNCTION_TEMPLATE_ARGS
  322. >::type
  323. invoker_type;
  324. typedef functor_manager<FunctionPtr> manager_type;
  325. };
  326. };
  327. #if BOOST_FUNCTION_NUM_ARGS > 0
  328. /* Retrieve the invoker for a member pointer. */
  329. template<>
  330. struct BOOST_FUNCTION_GET_INVOKER<member_ptr_tag>
  331. {
  332. template<typename MemberPtr,
  333. typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS>
  334. struct apply
  335. {
  336. typedef typename BOOST_FUNCTION_GET_MEMBER_INVOKER<
  337. MemberPtr,
  338. R BOOST_FUNCTION_COMMA
  339. BOOST_FUNCTION_TEMPLATE_ARGS
  340. >::type
  341. invoker_type;
  342. typedef functor_manager<MemberPtr> manager_type;
  343. };
  344. template<typename MemberPtr, typename Allocator,
  345. typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS>
  346. struct apply_a
  347. {
  348. typedef typename BOOST_FUNCTION_GET_MEMBER_INVOKER<
  349. MemberPtr,
  350. R BOOST_FUNCTION_COMMA
  351. BOOST_FUNCTION_TEMPLATE_ARGS
  352. >::type
  353. invoker_type;
  354. typedef functor_manager<MemberPtr> manager_type;
  355. };
  356. };
  357. #endif
  358. /* Retrieve the invoker for a function object. */
  359. template<>
  360. struct BOOST_FUNCTION_GET_INVOKER<function_obj_tag>
  361. {
  362. template<typename FunctionObj,
  363. typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS>
  364. struct apply
  365. {
  366. typedef typename BOOST_FUNCTION_GET_FUNCTION_OBJ_INVOKER<
  367. FunctionObj,
  368. R BOOST_FUNCTION_COMMA
  369. BOOST_FUNCTION_TEMPLATE_ARGS
  370. >::type
  371. invoker_type;
  372. typedef functor_manager<FunctionObj> manager_type;
  373. };
  374. template<typename FunctionObj, typename Allocator,
  375. typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS>
  376. struct apply_a
  377. {
  378. typedef typename BOOST_FUNCTION_GET_FUNCTION_OBJ_INVOKER<
  379. FunctionObj,
  380. R BOOST_FUNCTION_COMMA
  381. BOOST_FUNCTION_TEMPLATE_ARGS
  382. >::type
  383. invoker_type;
  384. typedef functor_manager_a<FunctionObj, Allocator> manager_type;
  385. };
  386. };
  387. /* Retrieve the invoker for a reference to a function object. */
  388. template<>
  389. struct BOOST_FUNCTION_GET_INVOKER<function_obj_ref_tag>
  390. {
  391. template<typename RefWrapper,
  392. typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS>
  393. struct apply
  394. {
  395. typedef typename BOOST_FUNCTION_GET_FUNCTION_REF_INVOKER<
  396. typename RefWrapper::type,
  397. R BOOST_FUNCTION_COMMA
  398. BOOST_FUNCTION_TEMPLATE_ARGS
  399. >::type
  400. invoker_type;
  401. typedef reference_manager<typename RefWrapper::type> manager_type;
  402. };
  403. template<typename RefWrapper, typename Allocator,
  404. typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS>
  405. struct apply_a
  406. {
  407. typedef typename BOOST_FUNCTION_GET_FUNCTION_REF_INVOKER<
  408. typename RefWrapper::type,
  409. R BOOST_FUNCTION_COMMA
  410. BOOST_FUNCTION_TEMPLATE_ARGS
  411. >::type
  412. invoker_type;
  413. typedef reference_manager<typename RefWrapper::type> manager_type;
  414. };
  415. };
  416. /**
  417. * vtable for a specific boost::function instance. This
  418. * structure must be an aggregate so that we can use static
  419. * initialization in boost::function's assign_to and assign_to_a
  420. * members. It therefore cannot have any constructors,
  421. * destructors, base classes, etc.
  422. */
  423. template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS>
  424. struct BOOST_FUNCTION_VTABLE
  425. {
  426. #ifndef BOOST_NO_VOID_RETURNS
  427. typedef R result_type;
  428. #else
  429. typedef typename function_return_type<R>::type result_type;
  430. #endif // BOOST_NO_VOID_RETURNS
  431. typedef result_type (*invoker_type)(function_buffer&
  432. BOOST_FUNCTION_COMMA
  433. BOOST_FUNCTION_TEMPLATE_ARGS);
  434. template<typename F>
  435. bool assign_to(F f, function_buffer& functor) const
  436. {
  437. typedef typename get_function_tag<F>::type tag;
  438. return assign_to(f, functor, tag());
  439. }
  440. template<typename F,typename Allocator>
  441. bool assign_to_a(F f, function_buffer& functor, Allocator a) const
  442. {
  443. typedef typename get_function_tag<F>::type tag;
  444. return assign_to_a(f, functor, a, tag());
  445. }
  446. void clear(function_buffer& functor) const
  447. {
  448. if (base.manager)
  449. base.manager(functor, functor, destroy_functor_tag);
  450. }
  451. private:
  452. // Function pointers
  453. template<typename FunctionPtr>
  454. bool
  455. assign_to(FunctionPtr f, function_buffer& functor, function_ptr_tag) const
  456. {
  457. this->clear(functor);
  458. if (f) {
  459. // should be a reinterpret cast, but some compilers insist
  460. // on giving cv-qualifiers to free functions
  461. functor.members.func_ptr = reinterpret_cast<void (*)()>(f);
  462. return true;
  463. } else {
  464. return false;
  465. }
  466. }
  467. template<typename FunctionPtr,typename Allocator>
  468. bool
  469. assign_to_a(FunctionPtr f, function_buffer& functor, Allocator, function_ptr_tag) const
  470. {
  471. return assign_to(f,functor,function_ptr_tag());
  472. }
  473. // Member pointers
  474. #if BOOST_FUNCTION_NUM_ARGS > 0
  475. template<typename MemberPtr>
  476. bool assign_to(MemberPtr f, function_buffer& functor, member_ptr_tag) const
  477. {
  478. // DPG TBD: Add explicit support for member function
  479. // objects, so we invoke through mem_fn() but we retain the
  480. // right target_type() values.
  481. if (f) {
  482. this->assign_to(boost::mem_fn(f), functor);
  483. return true;
  484. } else {
  485. return false;
  486. }
  487. }
  488. template<typename MemberPtr,typename Allocator>
  489. bool assign_to_a(MemberPtr f, function_buffer& functor, Allocator a, member_ptr_tag) const
  490. {
  491. // DPG TBD: Add explicit support for member function
  492. // objects, so we invoke through mem_fn() but we retain the
  493. // right target_type() values.
  494. if (f) {
  495. this->assign_to_a(boost::mem_fn(f), functor, a);
  496. return true;
  497. } else {
  498. return false;
  499. }
  500. }
  501. #endif // BOOST_FUNCTION_NUM_ARGS > 0
  502. // Function objects
  503. // Assign to a function object using the small object optimization
  504. template<typename FunctionObj>
  505. void
  506. assign_functor(FunctionObj f, function_buffer& functor, true_type) const
  507. {
  508. new (reinterpret_cast<void*>(functor.data)) FunctionObj(f);
  509. }
  510. template<typename FunctionObj,typename Allocator>
  511. void
  512. assign_functor_a(FunctionObj f, function_buffer& functor, Allocator, true_type) const
  513. {
  514. assign_functor(f,functor,true_type());
  515. }
  516. // Assign to a function object allocated on the heap.
  517. template<typename FunctionObj>
  518. void
  519. assign_functor(FunctionObj f, function_buffer& functor, false_type) const
  520. {
  521. functor.members.obj_ptr = new FunctionObj(f);
  522. }
  523. template<typename FunctionObj,typename Allocator>
  524. void
  525. assign_functor_a(FunctionObj f, function_buffer& functor, Allocator a, false_type) const
  526. {
  527. typedef functor_wrapper<FunctionObj,Allocator> functor_wrapper_type;
  528. #if defined(BOOST_NO_CXX11_ALLOCATOR)
  529. typedef typename Allocator::template rebind<functor_wrapper_type>::other
  530. wrapper_allocator_type;
  531. typedef typename wrapper_allocator_type::pointer wrapper_allocator_pointer_type;
  532. #else
  533. using wrapper_allocator_type = typename std::allocator_traits<Allocator>::template rebind_alloc<functor_wrapper_type>;
  534. using wrapper_allocator_pointer_type = typename std::allocator_traits<wrapper_allocator_type>::pointer;
  535. #endif
  536. wrapper_allocator_type wrapper_allocator(a);
  537. wrapper_allocator_pointer_type copy = wrapper_allocator.allocate(1);
  538. #if defined(BOOST_NO_CXX11_ALLOCATOR)
  539. wrapper_allocator.construct(copy, functor_wrapper_type(f,a));
  540. #else
  541. std::allocator_traits<wrapper_allocator_type>::construct(wrapper_allocator, copy, functor_wrapper_type(f,a));
  542. #endif
  543. functor_wrapper_type* new_f = static_cast<functor_wrapper_type*>(copy);
  544. functor.members.obj_ptr = new_f;
  545. }
  546. template<typename FunctionObj>
  547. bool
  548. assign_to(FunctionObj f, function_buffer& functor, function_obj_tag) const
  549. {
  550. if (!boost::detail::function::has_empty_target(boost::addressof(f))) {
  551. assign_functor(f, functor,
  552. integral_constant<bool, (function_allows_small_object_optimization<FunctionObj>::value)>());
  553. return true;
  554. } else {
  555. return false;
  556. }
  557. }
  558. template<typename FunctionObj,typename Allocator>
  559. bool
  560. assign_to_a(FunctionObj f, function_buffer& functor, Allocator a, function_obj_tag) const
  561. {
  562. if (!boost::detail::function::has_empty_target(boost::addressof(f))) {
  563. assign_functor_a(f, functor, a,
  564. integral_constant<bool, (function_allows_small_object_optimization<FunctionObj>::value)>());
  565. return true;
  566. } else {
  567. return false;
  568. }
  569. }
  570. // Reference to a function object
  571. template<typename FunctionObj>
  572. bool
  573. assign_to(const reference_wrapper<FunctionObj>& f,
  574. function_buffer& functor, function_obj_ref_tag) const
  575. {
  576. functor.members.obj_ref.obj_ptr = (void *)(f.get_pointer());
  577. functor.members.obj_ref.is_const_qualified = is_const<FunctionObj>::value;
  578. functor.members.obj_ref.is_volatile_qualified = is_volatile<FunctionObj>::value;
  579. return true;
  580. }
  581. template<typename FunctionObj,typename Allocator>
  582. bool
  583. assign_to_a(const reference_wrapper<FunctionObj>& f,
  584. function_buffer& functor, Allocator, function_obj_ref_tag) const
  585. {
  586. return assign_to(f,functor,function_obj_ref_tag());
  587. }
  588. public:
  589. vtable_base base;
  590. invoker_type invoker;
  591. };
  592. } // end namespace function
  593. } // end namespace detail
  594. template<
  595. typename R BOOST_FUNCTION_COMMA
  596. BOOST_FUNCTION_TEMPLATE_PARMS
  597. >
  598. class BOOST_FUNCTION_FUNCTION : public function_base
  599. {
  600. public:
  601. #ifndef BOOST_NO_VOID_RETURNS
  602. typedef R result_type;
  603. #else
  604. typedef typename boost::detail::function::function_return_type<R>::type
  605. result_type;
  606. #endif // BOOST_NO_VOID_RETURNS
  607. private:
  608. typedef boost::detail::function::BOOST_FUNCTION_VTABLE<
  609. R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_ARGS>
  610. vtable_type;
  611. vtable_type* get_vtable() const {
  612. return reinterpret_cast<vtable_type*>(
  613. reinterpret_cast<std::size_t>(vtable) & ~static_cast<std::size_t>(0x01));
  614. }
  615. struct clear_type {};
  616. public:
  617. BOOST_STATIC_CONSTANT(int, args = BOOST_FUNCTION_NUM_ARGS);
  618. // add signature for boost::lambda
  619. template<typename Args>
  620. struct sig
  621. {
  622. typedef result_type type;
  623. };
  624. #if BOOST_FUNCTION_NUM_ARGS == 1
  625. typedef T0 argument_type;
  626. #elif BOOST_FUNCTION_NUM_ARGS == 2
  627. typedef T0 first_argument_type;
  628. typedef T1 second_argument_type;
  629. #endif
  630. BOOST_STATIC_CONSTANT(int, arity = BOOST_FUNCTION_NUM_ARGS);
  631. BOOST_FUNCTION_ARG_TYPES
  632. typedef BOOST_FUNCTION_FUNCTION self_type;
  633. BOOST_DEFAULTED_FUNCTION(BOOST_FUNCTION_FUNCTION(), : function_base() {})
  634. // MSVC chokes if the following two constructors are collapsed into
  635. // one with a default parameter.
  636. template<typename Functor>
  637. BOOST_FUNCTION_FUNCTION(Functor BOOST_FUNCTION_TARGET_FIX(const &) f
  638. #ifndef BOOST_NO_SFINAE
  639. ,typename boost::enable_if_<
  640. !(is_integral<Functor>::value),
  641. int>::type = 0
  642. #endif // BOOST_NO_SFINAE
  643. ) :
  644. function_base()
  645. {
  646. this->assign_to(f);
  647. }
  648. template<typename Functor,typename Allocator>
  649. BOOST_FUNCTION_FUNCTION(Functor BOOST_FUNCTION_TARGET_FIX(const &) f, Allocator a
  650. #ifndef BOOST_NO_SFINAE
  651. ,typename boost::enable_if_<
  652. !(is_integral<Functor>::value),
  653. int>::type = 0
  654. #endif // BOOST_NO_SFINAE
  655. ) :
  656. function_base()
  657. {
  658. this->assign_to_a(f,a);
  659. }
  660. #ifndef BOOST_NO_SFINAE
  661. BOOST_FUNCTION_FUNCTION(clear_type*) : function_base() { }
  662. #else
  663. BOOST_FUNCTION_FUNCTION(int zero) : function_base()
  664. {
  665. BOOST_ASSERT(zero == 0);
  666. }
  667. #endif
  668. BOOST_FUNCTION_FUNCTION(const BOOST_FUNCTION_FUNCTION& f) : function_base()
  669. {
  670. this->assign_to_own(f);
  671. }
  672. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  673. BOOST_FUNCTION_FUNCTION(BOOST_FUNCTION_FUNCTION&& f) : function_base()
  674. {
  675. this->move_assign(f);
  676. }
  677. #endif
  678. ~BOOST_FUNCTION_FUNCTION() { clear(); }
  679. result_type operator()(BOOST_FUNCTION_PARMS) const
  680. {
  681. if (this->empty())
  682. boost::throw_exception(bad_function_call());
  683. return get_vtable()->invoker
  684. (this->functor BOOST_FUNCTION_COMMA BOOST_FUNCTION_ARGS);
  685. }
  686. // The distinction between when to use BOOST_FUNCTION_FUNCTION and
  687. // when to use self_type is obnoxious. MSVC cannot handle self_type as
  688. // the return type of these assignment operators, but Borland C++ cannot
  689. // handle BOOST_FUNCTION_FUNCTION as the type of the temporary to
  690. // construct.
  691. template<typename Functor>
  692. #ifndef BOOST_NO_SFINAE
  693. typename boost::enable_if_<
  694. !(is_integral<Functor>::value),
  695. BOOST_FUNCTION_FUNCTION&>::type
  696. #else
  697. BOOST_FUNCTION_FUNCTION&
  698. #endif
  699. operator=(Functor BOOST_FUNCTION_TARGET_FIX(const &) f)
  700. {
  701. this->clear();
  702. BOOST_TRY {
  703. this->assign_to(f);
  704. } BOOST_CATCH (...) {
  705. vtable = 0;
  706. BOOST_RETHROW;
  707. }
  708. BOOST_CATCH_END
  709. return *this;
  710. }
  711. template<typename Functor,typename Allocator>
  712. void assign(Functor BOOST_FUNCTION_TARGET_FIX(const &) f, Allocator a)
  713. {
  714. this->clear();
  715. BOOST_TRY{
  716. this->assign_to_a(f,a);
  717. } BOOST_CATCH (...) {
  718. vtable = 0;
  719. BOOST_RETHROW;
  720. }
  721. BOOST_CATCH_END
  722. }
  723. #ifndef BOOST_NO_SFINAE
  724. BOOST_FUNCTION_FUNCTION& operator=(clear_type*)
  725. {
  726. this->clear();
  727. return *this;
  728. }
  729. #else
  730. BOOST_FUNCTION_FUNCTION& operator=(int zero)
  731. {
  732. BOOST_ASSERT(zero == 0);
  733. this->clear();
  734. return *this;
  735. }
  736. #endif
  737. // Assignment from another BOOST_FUNCTION_FUNCTION
  738. BOOST_FUNCTION_FUNCTION& operator=(const BOOST_FUNCTION_FUNCTION& f)
  739. {
  740. if (&f == this)
  741. return *this;
  742. this->clear();
  743. BOOST_TRY {
  744. this->assign_to_own(f);
  745. } BOOST_CATCH (...) {
  746. vtable = 0;
  747. BOOST_RETHROW;
  748. }
  749. BOOST_CATCH_END
  750. return *this;
  751. }
  752. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  753. // Move assignment from another BOOST_FUNCTION_FUNCTION
  754. BOOST_FUNCTION_FUNCTION& operator=(BOOST_FUNCTION_FUNCTION&& f)
  755. {
  756. if (&f == this)
  757. return *this;
  758. this->clear();
  759. BOOST_TRY {
  760. this->move_assign(f);
  761. } BOOST_CATCH (...) {
  762. vtable = 0;
  763. BOOST_RETHROW;
  764. }
  765. BOOST_CATCH_END
  766. return *this;
  767. }
  768. #endif
  769. void swap(BOOST_FUNCTION_FUNCTION& other)
  770. {
  771. if (&other == this)
  772. return;
  773. BOOST_FUNCTION_FUNCTION tmp;
  774. tmp.move_assign(*this);
  775. this->move_assign(other);
  776. other.move_assign(tmp);
  777. }
  778. // Clear out a target, if there is one
  779. void clear()
  780. {
  781. if (vtable) {
  782. if (!this->has_trivial_copy_and_destroy())
  783. get_vtable()->clear(this->functor);
  784. vtable = 0;
  785. }
  786. }
  787. #if (defined __SUNPRO_CC) && (__SUNPRO_CC <= 0x530) && !(defined BOOST_NO_COMPILER_CONFIG)
  788. // Sun C++ 5.3 can't handle the safe_bool idiom, so don't use it
  789. operator bool () const { return !this->empty(); }
  790. #else
  791. private:
  792. struct dummy {
  793. void nonnull() {}
  794. };
  795. typedef void (dummy::*safe_bool)();
  796. public:
  797. operator safe_bool () const
  798. { return (this->empty())? 0 : &dummy::nonnull; }
  799. bool operator!() const
  800. { return this->empty(); }
  801. #endif
  802. private:
  803. void assign_to_own(const BOOST_FUNCTION_FUNCTION& f)
  804. {
  805. if (!f.empty()) {
  806. this->vtable = f.vtable;
  807. if (this->has_trivial_copy_and_destroy())
  808. // Don't operate on storage directly since union type doesn't relax
  809. // strict aliasing rules, despite of having member char type.
  810. std::memcpy(this->functor.data, f.functor.data, sizeof(boost::detail::function::function_buffer));
  811. else
  812. get_vtable()->base.manager(f.functor, this->functor,
  813. boost::detail::function::clone_functor_tag);
  814. }
  815. }
  816. template<typename Functor>
  817. void assign_to(Functor f)
  818. {
  819. using boost::detail::function::vtable_base;
  820. typedef typename boost::detail::function::get_function_tag<Functor>::type tag;
  821. typedef boost::detail::function::BOOST_FUNCTION_GET_INVOKER<tag> get_invoker;
  822. typedef typename get_invoker::
  823. template apply<Functor, R BOOST_FUNCTION_COMMA
  824. BOOST_FUNCTION_TEMPLATE_ARGS>
  825. handler_type;
  826. typedef typename handler_type::invoker_type invoker_type;
  827. typedef typename handler_type::manager_type manager_type;
  828. // Note: it is extremely important that this initialization use
  829. // static initialization. Otherwise, we will have a race
  830. // condition here in multi-threaded code. See
  831. // http://thread.gmane.org/gmane.comp.lib.boost.devel/164902/.
  832. static const vtable_type stored_vtable =
  833. { { &manager_type::manage }, &invoker_type::invoke };
  834. if (stored_vtable.assign_to(f, functor)) {
  835. std::size_t value = reinterpret_cast<std::size_t>(&stored_vtable.base);
  836. // coverity[pointless_expression]: suppress coverity warnings on apparant if(const).
  837. if (boost::has_trivial_copy_constructor<Functor>::value &&
  838. boost::has_trivial_destructor<Functor>::value &&
  839. boost::detail::function::function_allows_small_object_optimization<Functor>::value)
  840. value |= static_cast<std::size_t>(0x01);
  841. vtable = reinterpret_cast<boost::detail::function::vtable_base *>(value);
  842. } else
  843. vtable = 0;
  844. }
  845. template<typename Functor,typename Allocator>
  846. void assign_to_a(Functor f,Allocator a)
  847. {
  848. using boost::detail::function::vtable_base;
  849. typedef typename boost::detail::function::get_function_tag<Functor>::type tag;
  850. typedef boost::detail::function::BOOST_FUNCTION_GET_INVOKER<tag> get_invoker;
  851. typedef typename get_invoker::
  852. template apply_a<Functor, Allocator, R BOOST_FUNCTION_COMMA
  853. BOOST_FUNCTION_TEMPLATE_ARGS>
  854. handler_type;
  855. typedef typename handler_type::invoker_type invoker_type;
  856. typedef typename handler_type::manager_type manager_type;
  857. // Note: it is extremely important that this initialization use
  858. // static initialization. Otherwise, we will have a race
  859. // condition here in multi-threaded code. See
  860. // http://thread.gmane.org/gmane.comp.lib.boost.devel/164902/.
  861. static const vtable_type stored_vtable =
  862. { { &manager_type::manage }, &invoker_type::invoke };
  863. if (stored_vtable.assign_to_a(f, functor, a)) {
  864. std::size_t value = reinterpret_cast<std::size_t>(&stored_vtable.base);
  865. // coverity[pointless_expression]: suppress coverity warnings on apparant if(const).
  866. if (boost::has_trivial_copy_constructor<Functor>::value &&
  867. boost::has_trivial_destructor<Functor>::value &&
  868. boost::detail::function::function_allows_small_object_optimization<Functor>::value)
  869. value |= static_cast<std::size_t>(0x01);
  870. vtable = reinterpret_cast<boost::detail::function::vtable_base *>(value);
  871. } else
  872. vtable = 0;
  873. }
  874. // Moves the value from the specified argument to *this. If the argument
  875. // has its function object allocated on the heap, move_assign will pass
  876. // its buffer to *this, and set the argument's buffer pointer to NULL.
  877. void move_assign(BOOST_FUNCTION_FUNCTION& f)
  878. {
  879. if (&f == this)
  880. return;
  881. BOOST_TRY {
  882. if (!f.empty()) {
  883. this->vtable = f.vtable;
  884. if (this->has_trivial_copy_and_destroy())
  885. // Don't operate on storage directly since union type doesn't relax
  886. // strict aliasing rules, despite of having member char type.
  887. std::memcpy(this->functor.data, f.functor.data, sizeof(this->functor.data));
  888. else
  889. get_vtable()->base.manager(f.functor, this->functor,
  890. boost::detail::function::move_functor_tag);
  891. f.vtable = 0;
  892. } else {
  893. clear();
  894. }
  895. } BOOST_CATCH (...) {
  896. vtable = 0;
  897. BOOST_RETHROW;
  898. }
  899. BOOST_CATCH_END
  900. }
  901. };
  902. template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS>
  903. inline void swap(BOOST_FUNCTION_FUNCTION<
  904. R BOOST_FUNCTION_COMMA
  905. BOOST_FUNCTION_TEMPLATE_ARGS
  906. >& f1,
  907. BOOST_FUNCTION_FUNCTION<
  908. R BOOST_FUNCTION_COMMA
  909. BOOST_FUNCTION_TEMPLATE_ARGS
  910. >& f2)
  911. {
  912. f1.swap(f2);
  913. }
  914. // Poison comparisons between boost::function objects of the same type.
  915. template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS>
  916. void operator==(const BOOST_FUNCTION_FUNCTION<
  917. R BOOST_FUNCTION_COMMA
  918. BOOST_FUNCTION_TEMPLATE_ARGS>&,
  919. const BOOST_FUNCTION_FUNCTION<
  920. R BOOST_FUNCTION_COMMA
  921. BOOST_FUNCTION_TEMPLATE_ARGS>&);
  922. template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS>
  923. void operator!=(const BOOST_FUNCTION_FUNCTION<
  924. R BOOST_FUNCTION_COMMA
  925. BOOST_FUNCTION_TEMPLATE_ARGS>&,
  926. const BOOST_FUNCTION_FUNCTION<
  927. R BOOST_FUNCTION_COMMA
  928. BOOST_FUNCTION_TEMPLATE_ARGS>& );
  929. #if !defined(BOOST_FUNCTION_NO_FUNCTION_TYPE_SYNTAX)
  930. #if BOOST_FUNCTION_NUM_ARGS == 0
  931. #define BOOST_FUNCTION_PARTIAL_SPEC R (void)
  932. #else
  933. #define BOOST_FUNCTION_PARTIAL_SPEC R (BOOST_FUNCTION_TEMPLATE_ARGS)
  934. #endif
  935. template<typename R BOOST_FUNCTION_COMMA
  936. BOOST_FUNCTION_TEMPLATE_PARMS>
  937. class function<BOOST_FUNCTION_PARTIAL_SPEC>
  938. : public BOOST_FUNCTION_FUNCTION<R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_ARGS>
  939. {
  940. typedef BOOST_FUNCTION_FUNCTION<R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_ARGS> base_type;
  941. typedef function self_type;
  942. struct clear_type {};
  943. public:
  944. BOOST_DEFAULTED_FUNCTION(function(), : base_type() {})
  945. template<typename Functor>
  946. function(Functor f
  947. #ifndef BOOST_NO_SFINAE
  948. ,typename boost::enable_if_<
  949. !(is_integral<Functor>::value),
  950. int>::type = 0
  951. #endif
  952. ) :
  953. base_type(f)
  954. {
  955. }
  956. template<typename Functor,typename Allocator>
  957. function(Functor f, Allocator a
  958. #ifndef BOOST_NO_SFINAE
  959. ,typename boost::enable_if_<
  960. !(is_integral<Functor>::value),
  961. int>::type = 0
  962. #endif
  963. ) :
  964. base_type(f,a)
  965. {
  966. }
  967. #ifndef BOOST_NO_SFINAE
  968. function(clear_type*) : base_type() {}
  969. #endif
  970. function(const self_type& f) : base_type(static_cast<const base_type&>(f)){}
  971. function(const base_type& f) : base_type(static_cast<const base_type&>(f)){}
  972. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  973. // Move constructors
  974. function(self_type&& f): base_type(static_cast<base_type&&>(f)){}
  975. function(base_type&& f): base_type(static_cast<base_type&&>(f)){}
  976. #endif
  977. self_type& operator=(const self_type& f)
  978. {
  979. self_type(f).swap(*this);
  980. return *this;
  981. }
  982. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  983. self_type& operator=(self_type&& f)
  984. {
  985. self_type(static_cast<self_type&&>(f)).swap(*this);
  986. return *this;
  987. }
  988. #endif
  989. template<typename Functor>
  990. #ifndef BOOST_NO_SFINAE
  991. typename boost::enable_if_<
  992. !(is_integral<Functor>::value),
  993. self_type&>::type
  994. #else
  995. self_type&
  996. #endif
  997. operator=(Functor f)
  998. {
  999. self_type(f).swap(*this);
  1000. return *this;
  1001. }
  1002. #ifndef BOOST_NO_SFINAE
  1003. self_type& operator=(clear_type*)
  1004. {
  1005. this->clear();
  1006. return *this;
  1007. }
  1008. #endif
  1009. self_type& operator=(const base_type& f)
  1010. {
  1011. self_type(f).swap(*this);
  1012. return *this;
  1013. }
  1014. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  1015. self_type& operator=(base_type&& f)
  1016. {
  1017. self_type(static_cast<base_type&&>(f)).swap(*this);
  1018. return *this;
  1019. }
  1020. #endif
  1021. };
  1022. #undef BOOST_FUNCTION_PARTIAL_SPEC
  1023. #endif // have partial specialization
  1024. } // end namespace boost
  1025. // Cleanup after ourselves...
  1026. #undef BOOST_FUNCTION_VTABLE
  1027. #undef BOOST_FUNCTION_COMMA
  1028. #undef BOOST_FUNCTION_FUNCTION
  1029. #undef BOOST_FUNCTION_FUNCTION_INVOKER
  1030. #undef BOOST_FUNCTION_VOID_FUNCTION_INVOKER
  1031. #undef BOOST_FUNCTION_FUNCTION_OBJ_INVOKER
  1032. #undef BOOST_FUNCTION_VOID_FUNCTION_OBJ_INVOKER
  1033. #undef BOOST_FUNCTION_FUNCTION_REF_INVOKER
  1034. #undef BOOST_FUNCTION_VOID_FUNCTION_REF_INVOKER
  1035. #undef BOOST_FUNCTION_MEMBER_INVOKER
  1036. #undef BOOST_FUNCTION_VOID_MEMBER_INVOKER
  1037. #undef BOOST_FUNCTION_GET_FUNCTION_INVOKER
  1038. #undef BOOST_FUNCTION_GET_FUNCTION_OBJ_INVOKER
  1039. #undef BOOST_FUNCTION_GET_FUNCTION_REF_INVOKER
  1040. #undef BOOST_FUNCTION_GET_MEM_FUNCTION_INVOKER
  1041. #undef BOOST_FUNCTION_GET_INVOKER
  1042. #undef BOOST_FUNCTION_TEMPLATE_PARMS
  1043. #undef BOOST_FUNCTION_TEMPLATE_ARGS
  1044. #undef BOOST_FUNCTION_PARMS
  1045. #undef BOOST_FUNCTION_PARM
  1046. #ifdef BOOST_FUNCTION_ARG
  1047. # undef BOOST_FUNCTION_ARG
  1048. #endif
  1049. #undef BOOST_FUNCTION_ARGS
  1050. #undef BOOST_FUNCTION_ARG_TYPE
  1051. #undef BOOST_FUNCTION_ARG_TYPES
  1052. #undef BOOST_FUNCTION_VOID_RETURN_TYPE
  1053. #undef BOOST_FUNCTION_RETURN
  1054. #if defined(BOOST_MSVC)
  1055. # pragma warning( pop )
  1056. #endif