2 //===----------------------------------------------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef _LIBCPP_FUNCTIONAL_03
12 #define _LIBCPP_FUNCTIONAL_03
14 // manual variadic expansion for <functional>
16 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17 #pragma GCC system_header
22 : public __weak_result_type<_Tp>
31 _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) : __f_(__f) {}
35 typename __invoke_return<type>::type
38 return __invoke(__f_);
42 typename __invoke_return0<type, _A0>::type
43 operator() (_A0& __a0) const
45 return __invoke(__f_, __a0);
48 template <class _A0, class _A1>
49 typename __invoke_return1<type, _A0, _A1>::type
50 operator() (_A0& __a0, _A1& __a1) const
52 return __invoke(__f_, __a0, __a1);
55 template <class _A0, class _A1, class _A2>
56 typename __invoke_return2<type, _A0, _A1, _A2>::type
57 operator() (_A0& __a0, _A1& __a1, _A2& __a2) const
59 return __invoke(__f_, __a0, __a1, __a2);
63 template<class _Rp, class _Tp>
64 inline _LIBCPP_INLINE_VISIBILITY
66 mem_fn(_Rp _Tp::* __pm)
68 return __mem_fn<_Rp _Tp::*>(__pm);
71 template<class _Rp, class _Tp>
72 inline _LIBCPP_INLINE_VISIBILITY
73 __mem_fn<_Rp (_Tp::*)()>
74 mem_fn(_Rp (_Tp::* __pm)())
76 return __mem_fn<_Rp (_Tp::*)()>(__pm);
79 template<class _Rp, class _Tp, class _A0>
80 inline _LIBCPP_INLINE_VISIBILITY
81 __mem_fn<_Rp (_Tp::*)(_A0)>
82 mem_fn(_Rp (_Tp::* __pm)(_A0))
84 return __mem_fn<_Rp (_Tp::*)(_A0)>(__pm);
87 template<class _Rp, class _Tp, class _A0, class _A1>
88 inline _LIBCPP_INLINE_VISIBILITY
89 __mem_fn<_Rp (_Tp::*)(_A0, _A1)>
90 mem_fn(_Rp (_Tp::* __pm)(_A0, _A1))
92 return __mem_fn<_Rp (_Tp::*)(_A0, _A1)>(__pm);
95 template<class _Rp, class _Tp, class _A0, class _A1, class _A2>
96 inline _LIBCPP_INLINE_VISIBILITY
97 __mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2)>
98 mem_fn(_Rp (_Tp::* __pm)(_A0, _A1, _A2))
100 return __mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2)>(__pm);
103 template<class _Rp, class _Tp>
104 inline _LIBCPP_INLINE_VISIBILITY
105 __mem_fn<_Rp (_Tp::*)() const>
106 mem_fn(_Rp (_Tp::* __pm)() const)
108 return __mem_fn<_Rp (_Tp::*)() const>(__pm);
111 template<class _Rp, class _Tp, class _A0>
112 inline _LIBCPP_INLINE_VISIBILITY
113 __mem_fn<_Rp (_Tp::*)(_A0) const>
114 mem_fn(_Rp (_Tp::* __pm)(_A0) const)
116 return __mem_fn<_Rp (_Tp::*)(_A0) const>(__pm);
119 template<class _Rp, class _Tp, class _A0, class _A1>
120 inline _LIBCPP_INLINE_VISIBILITY
121 __mem_fn<_Rp (_Tp::*)(_A0, _A1) const>
122 mem_fn(_Rp (_Tp::* __pm)(_A0, _A1) const)
124 return __mem_fn<_Rp (_Tp::*)(_A0, _A1) const>(__pm);
127 template<class _Rp, class _Tp, class _A0, class _A1, class _A2>
128 inline _LIBCPP_INLINE_VISIBILITY
129 __mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2) const>
130 mem_fn(_Rp (_Tp::* __pm)(_A0, _A1, _A2) const)
132 return __mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2) const>(__pm);
135 template<class _Rp, class _Tp>
136 inline _LIBCPP_INLINE_VISIBILITY
137 __mem_fn<_Rp (_Tp::*)() volatile>
138 mem_fn(_Rp (_Tp::* __pm)() volatile)
140 return __mem_fn<_Rp (_Tp::*)() volatile>(__pm);
143 template<class _Rp, class _Tp, class _A0>
144 inline _LIBCPP_INLINE_VISIBILITY
145 __mem_fn<_Rp (_Tp::*)(_A0) volatile>
146 mem_fn(_Rp (_Tp::* __pm)(_A0) volatile)
148 return __mem_fn<_Rp (_Tp::*)(_A0) volatile>(__pm);
151 template<class _Rp, class _Tp, class _A0, class _A1>
152 inline _LIBCPP_INLINE_VISIBILITY
153 __mem_fn<_Rp (_Tp::*)(_A0, _A1) volatile>
154 mem_fn(_Rp (_Tp::* __pm)(_A0, _A1) volatile)
156 return __mem_fn<_Rp (_Tp::*)(_A0, _A1) volatile>(__pm);
159 template<class _Rp, class _Tp, class _A0, class _A1, class _A2>
160 inline _LIBCPP_INLINE_VISIBILITY
161 __mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2) volatile>
162 mem_fn(_Rp (_Tp::* __pm)(_A0, _A1, _A2) volatile)
164 return __mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2) volatile>(__pm);
167 template<class _Rp, class _Tp>
168 inline _LIBCPP_INLINE_VISIBILITY
169 __mem_fn<_Rp (_Tp::*)() const volatile>
170 mem_fn(_Rp (_Tp::* __pm)() const volatile)
172 return __mem_fn<_Rp (_Tp::*)() const volatile>(__pm);
175 template<class _Rp, class _Tp, class _A0>
176 inline _LIBCPP_INLINE_VISIBILITY
177 __mem_fn<_Rp (_Tp::*)(_A0) const volatile>
178 mem_fn(_Rp (_Tp::* __pm)(_A0) const volatile)
180 return __mem_fn<_Rp (_Tp::*)(_A0) const volatile>(__pm);
183 template<class _Rp, class _Tp, class _A0, class _A1>
184 inline _LIBCPP_INLINE_VISIBILITY
185 __mem_fn<_Rp (_Tp::*)(_A0, _A1) const volatile>
186 mem_fn(_Rp (_Tp::* __pm)(_A0, _A1) const volatile)
188 return __mem_fn<_Rp (_Tp::*)(_A0, _A1) const volatile>(__pm);
191 template<class _Rp, class _Tp, class _A0, class _A1, class _A2>
192 inline _LIBCPP_INLINE_VISIBILITY
193 __mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2) const volatile>
194 mem_fn(_Rp (_Tp::* __pm)(_A0, _A1, _A2) const volatile)
196 return __mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2) const volatile>(__pm);
201 class _LIBCPP_EXCEPTION_ABI bad_function_call
206 template<class _Fp> class _LIBCPP_TYPE_VIS_ONLY function; // undefined
212 struct __maybe_derive_from_unary_function
216 template<class _Rp, class _A1>
217 struct __maybe_derive_from_unary_function<_Rp(_A1)>
218 : public unary_function<_A1, _Rp>
223 struct __maybe_derive_from_binary_function
227 template<class _Rp, class _A1, class _A2>
228 struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
229 : public binary_function<_A1, _A2, _Rp>
233 template<class _Fp> class __base;
238 __base(const __base&);
239 __base& operator=(const __base&);
243 virtual __base* __clone() const = 0;
244 virtual void __clone(__base*) const = 0;
245 virtual void destroy() = 0;
246 virtual void destroy_deallocate() = 0;
247 virtual _Rp operator()() = 0;
248 #ifndef _LIBCPP_NO_RTTI
249 virtual const void* target(const type_info&) const = 0;
250 virtual const std::type_info& target_type() const = 0;
251 #endif // _LIBCPP_NO_RTTI
254 template<class _Rp, class _A0>
255 class __base<_Rp(_A0)>
257 __base(const __base&);
258 __base& operator=(const __base&);
262 virtual __base* __clone() const = 0;
263 virtual void __clone(__base*) const = 0;
264 virtual void destroy() = 0;
265 virtual void destroy_deallocate() = 0;
266 virtual _Rp operator()(_A0) = 0;
267 #ifndef _LIBCPP_NO_RTTI
268 virtual const void* target(const type_info&) const = 0;
269 virtual const std::type_info& target_type() const = 0;
270 #endif // _LIBCPP_NO_RTTI
273 template<class _Rp, class _A0, class _A1>
274 class __base<_Rp(_A0, _A1)>
276 __base(const __base&);
277 __base& operator=(const __base&);
281 virtual __base* __clone() const = 0;
282 virtual void __clone(__base*) const = 0;
283 virtual void destroy() = 0;
284 virtual void destroy_deallocate() = 0;
285 virtual _Rp operator()(_A0, _A1) = 0;
286 #ifndef _LIBCPP_NO_RTTI
287 virtual const void* target(const type_info&) const = 0;
288 virtual const std::type_info& target_type() const = 0;
289 #endif // _LIBCPP_NO_RTTI
292 template<class _Rp, class _A0, class _A1, class _A2>
293 class __base<_Rp(_A0, _A1, _A2)>
295 __base(const __base&);
296 __base& operator=(const __base&);
300 virtual __base* __clone() const = 0;
301 virtual void __clone(__base*) const = 0;
302 virtual void destroy() = 0;
303 virtual void destroy_deallocate() = 0;
304 virtual _Rp operator()(_A0, _A1, _A2) = 0;
305 #ifndef _LIBCPP_NO_RTTI
306 virtual const void* target(const type_info&) const = 0;
307 virtual const std::type_info& target_type() const = 0;
308 #endif // _LIBCPP_NO_RTTI
311 template<class _FD, class _Alloc, class _FB> class __func;
313 template<class _Fp, class _Alloc, class _Rp>
314 class __func<_Fp, _Alloc, _Rp()>
315 : public __base<_Rp()>
317 __compressed_pair<_Fp, _Alloc> __f_;
319 explicit __func(_Fp __f) : __f_(_VSTD::move(__f)) {}
320 explicit __func(_Fp __f, _Alloc __a) : __f_(_VSTD::move(__f), _VSTD::move(__a)) {}
321 virtual __base<_Rp()>* __clone() const;
322 virtual void __clone(__base<_Rp()>*) const;
323 virtual void destroy();
324 virtual void destroy_deallocate();
325 virtual _Rp operator()();
326 #ifndef _LIBCPP_NO_RTTI
327 virtual const void* target(const type_info&) const;
328 virtual const std::type_info& target_type() const;
329 #endif // _LIBCPP_NO_RTTI
332 template<class _Fp, class _Alloc, class _Rp>
334 __func<_Fp, _Alloc, _Rp()>::__clone() const
336 typedef allocator_traits<_Alloc> __alloc_traits;
337 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
338 _Ap __a(__f_.second());
339 typedef __allocator_destructor<_Ap> _Dp;
340 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
341 ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
342 return __hold.release();
345 template<class _Fp, class _Alloc, class _Rp>
347 __func<_Fp, _Alloc, _Rp()>::__clone(__base<_Rp()>* __p) const
349 ::new (__p) __func(__f_.first(), __f_.second());
352 template<class _Fp, class _Alloc, class _Rp>
354 __func<_Fp, _Alloc, _Rp()>::destroy()
356 __f_.~__compressed_pair<_Fp, _Alloc>();
359 template<class _Fp, class _Alloc, class _Rp>
361 __func<_Fp, _Alloc, _Rp()>::destroy_deallocate()
363 typedef allocator_traits<_Alloc> __alloc_traits;
364 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
365 _Ap __a(__f_.second());
366 __f_.~__compressed_pair<_Fp, _Alloc>();
367 __a.deallocate(this, 1);
370 template<class _Fp, class _Alloc, class _Rp>
372 __func<_Fp, _Alloc, _Rp()>::operator()()
374 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
375 return _Invoker::__call(__f_.first());
378 #ifndef _LIBCPP_NO_RTTI
380 template<class _Fp, class _Alloc, class _Rp>
382 __func<_Fp, _Alloc, _Rp()>::target(const type_info& __ti) const
384 if (__ti == typeid(_Fp))
385 return &__f_.first();
386 return (const void*)0;
389 template<class _Fp, class _Alloc, class _Rp>
390 const std::type_info&
391 __func<_Fp, _Alloc, _Rp()>::target_type() const
396 #endif // _LIBCPP_NO_RTTI
398 template<class _Fp, class _Alloc, class _Rp, class _A0>
399 class __func<_Fp, _Alloc, _Rp(_A0)>
400 : public __base<_Rp(_A0)>
402 __compressed_pair<_Fp, _Alloc> __f_;
404 _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f) : __f_(_VSTD::move(__f)) {}
405 _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f, _Alloc __a)
406 : __f_(_VSTD::move(__f), _VSTD::move(__a)) {}
407 virtual __base<_Rp(_A0)>* __clone() const;
408 virtual void __clone(__base<_Rp(_A0)>*) const;
409 virtual void destroy();
410 virtual void destroy_deallocate();
411 virtual _Rp operator()(_A0);
412 #ifndef _LIBCPP_NO_RTTI
413 virtual const void* target(const type_info&) const;
414 virtual const std::type_info& target_type() const;
415 #endif // _LIBCPP_NO_RTTI
418 template<class _Fp, class _Alloc, class _Rp, class _A0>
420 __func<_Fp, _Alloc, _Rp(_A0)>::__clone() const
422 typedef allocator_traits<_Alloc> __alloc_traits;
423 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
424 _Ap __a(__f_.second());
425 typedef __allocator_destructor<_Ap> _Dp;
426 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
427 ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
428 return __hold.release();
431 template<class _Fp, class _Alloc, class _Rp, class _A0>
433 __func<_Fp, _Alloc, _Rp(_A0)>::__clone(__base<_Rp(_A0)>* __p) const
435 ::new (__p) __func(__f_.first(), __f_.second());
438 template<class _Fp, class _Alloc, class _Rp, class _A0>
440 __func<_Fp, _Alloc, _Rp(_A0)>::destroy()
442 __f_.~__compressed_pair<_Fp, _Alloc>();
445 template<class _Fp, class _Alloc, class _Rp, class _A0>
447 __func<_Fp, _Alloc, _Rp(_A0)>::destroy_deallocate()
449 typedef allocator_traits<_Alloc> __alloc_traits;
450 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
451 _Ap __a(__f_.second());
452 __f_.~__compressed_pair<_Fp, _Alloc>();
453 __a.deallocate(this, 1);
456 template<class _Fp, class _Alloc, class _Rp, class _A0>
458 __func<_Fp, _Alloc, _Rp(_A0)>::operator()(_A0 __a0)
460 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
461 return _Invoker::__call(__f_.first(), __a0);
464 #ifndef _LIBCPP_NO_RTTI
466 template<class _Fp, class _Alloc, class _Rp, class _A0>
468 __func<_Fp, _Alloc, _Rp(_A0)>::target(const type_info& __ti) const
470 if (__ti == typeid(_Fp))
471 return &__f_.first();
472 return (const void*)0;
475 template<class _Fp, class _Alloc, class _Rp, class _A0>
476 const std::type_info&
477 __func<_Fp, _Alloc, _Rp(_A0)>::target_type() const
482 #endif // _LIBCPP_NO_RTTI
484 template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1>
485 class __func<_Fp, _Alloc, _Rp(_A0, _A1)>
486 : public __base<_Rp(_A0, _A1)>
488 __compressed_pair<_Fp, _Alloc> __f_;
490 _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f) : __f_(_VSTD::move(__f)) {}
491 _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f, _Alloc __a)
492 : __f_(_VSTD::move(__f), _VSTD::move(__a)) {}
493 virtual __base<_Rp(_A0, _A1)>* __clone() const;
494 virtual void __clone(__base<_Rp(_A0, _A1)>*) const;
495 virtual void destroy();
496 virtual void destroy_deallocate();
497 virtual _Rp operator()(_A0, _A1);
498 #ifndef _LIBCPP_NO_RTTI
499 virtual const void* target(const type_info&) const;
500 virtual const std::type_info& target_type() const;
501 #endif // _LIBCPP_NO_RTTI
504 template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1>
505 __base<_Rp(_A0, _A1)>*
506 __func<_Fp, _Alloc, _Rp(_A0, _A1)>::__clone() const
508 typedef allocator_traits<_Alloc> __alloc_traits;
509 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
510 _Ap __a(__f_.second());
511 typedef __allocator_destructor<_Ap> _Dp;
512 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
513 ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
514 return __hold.release();
517 template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1>
519 __func<_Fp, _Alloc, _Rp(_A0, _A1)>::__clone(__base<_Rp(_A0, _A1)>* __p) const
521 ::new (__p) __func(__f_.first(), __f_.second());
524 template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1>
526 __func<_Fp, _Alloc, _Rp(_A0, _A1)>::destroy()
528 __f_.~__compressed_pair<_Fp, _Alloc>();
531 template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1>
533 __func<_Fp, _Alloc, _Rp(_A0, _A1)>::destroy_deallocate()
535 typedef allocator_traits<_Alloc> __alloc_traits;
536 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
537 _Ap __a(__f_.second());
538 __f_.~__compressed_pair<_Fp, _Alloc>();
539 __a.deallocate(this, 1);
542 template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1>
544 __func<_Fp, _Alloc, _Rp(_A0, _A1)>::operator()(_A0 __a0, _A1 __a1)
546 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
547 return _Invoker::__call(__f_.first(), __a0, __a1);
550 #ifndef _LIBCPP_NO_RTTI
552 template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1>
554 __func<_Fp, _Alloc, _Rp(_A0, _A1)>::target(const type_info& __ti) const
556 if (__ti == typeid(_Fp))
557 return &__f_.first();
558 return (const void*)0;
561 template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1>
562 const std::type_info&
563 __func<_Fp, _Alloc, _Rp(_A0, _A1)>::target_type() const
568 #endif // _LIBCPP_NO_RTTI
570 template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2>
571 class __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>
572 : public __base<_Rp(_A0, _A1, _A2)>
574 __compressed_pair<_Fp, _Alloc> __f_;
576 _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f) : __f_(_VSTD::move(__f)) {}
577 _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f, _Alloc __a)
578 : __f_(_VSTD::move(__f), _VSTD::move(__a)) {}
579 virtual __base<_Rp(_A0, _A1, _A2)>* __clone() const;
580 virtual void __clone(__base<_Rp(_A0, _A1, _A2)>*) const;
581 virtual void destroy();
582 virtual void destroy_deallocate();
583 virtual _Rp operator()(_A0, _A1, _A2);
584 #ifndef _LIBCPP_NO_RTTI
585 virtual const void* target(const type_info&) const;
586 virtual const std::type_info& target_type() const;
587 #endif // _LIBCPP_NO_RTTI
590 template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2>
591 __base<_Rp(_A0, _A1, _A2)>*
592 __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::__clone() const
594 typedef allocator_traits<_Alloc> __alloc_traits;
595 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
596 _Ap __a(__f_.second());
597 typedef __allocator_destructor<_Ap> _Dp;
598 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
599 ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
600 return __hold.release();
603 template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2>
605 __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::__clone(__base<_Rp(_A0, _A1, _A2)>* __p) const
607 ::new (__p) __func(__f_.first(), __f_.second());
610 template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2>
612 __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::destroy()
614 __f_.~__compressed_pair<_Fp, _Alloc>();
617 template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2>
619 __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::destroy_deallocate()
621 typedef allocator_traits<_Alloc> __alloc_traits;
622 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
623 _Ap __a(__f_.second());
624 __f_.~__compressed_pair<_Fp, _Alloc>();
625 __a.deallocate(this, 1);
628 template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2>
630 __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::operator()(_A0 __a0, _A1 __a1, _A2 __a2)
632 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
633 return _Invoker::__call(__f_.first(), __a0, __a1, __a2);
636 #ifndef _LIBCPP_NO_RTTI
638 template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2>
640 __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::target(const type_info& __ti) const
642 if (__ti == typeid(_Fp))
643 return &__f_.first();
644 return (const void*)0;
647 template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2>
648 const std::type_info&
649 __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::target_type() const
654 #endif // _LIBCPP_NO_RTTI
659 class _LIBCPP_TYPE_VIS_ONLY function<_Rp()>
661 typedef __function::__base<_Rp()> __base;
662 aligned_storage<3*sizeof(void*)>::type __buf_;
666 _LIBCPP_INLINE_VISIBILITY
667 static bool __not_null(const _Fp&) {return true;}
669 _LIBCPP_INLINE_VISIBILITY
670 static bool __not_null(_R2 (*__p)()) {return __p;}
672 _LIBCPP_INLINE_VISIBILITY
673 static bool __not_null(const function<_R2()>& __p) {return __p;}
675 typedef _Rp result_type;
677 // 20.7.16.2.1, construct/copy/destroy:
678 _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {}
679 _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {}
680 function(const function&);
683 typename enable_if<!is_integral<_Fp>::value>::type* = 0);
685 template<class _Alloc>
686 _LIBCPP_INLINE_VISIBILITY
687 function(allocator_arg_t, const _Alloc&) : __f_(0) {}
688 template<class _Alloc>
689 _LIBCPP_INLINE_VISIBILITY
690 function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {}
691 template<class _Alloc>
692 function(allocator_arg_t, const _Alloc&, const function&);
693 template<class _Fp, class _Alloc>
694 function(allocator_arg_t, const _Alloc& __a, _Fp __f,
695 typename enable_if<!is_integral<_Fp>::value>::type* = 0);
697 function& operator=(const function&);
698 function& operator=(nullptr_t);
702 !is_integral<_Fp>::value,
709 // 20.7.16.2.2, function modifiers:
710 void swap(function&);
711 template<class _Fp, class _Alloc>
712 _LIBCPP_INLINE_VISIBILITY
713 void assign(_Fp __f, const _Alloc& __a)
714 {function(allocator_arg, __a, __f).swap(*this);}
716 // 20.7.16.2.3, function capacity:
717 _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;}
720 // deleted overloads close possible hole in the type system
722 bool operator==(const function<_R2()>&) const;// = delete;
724 bool operator!=(const function<_R2()>&) const;// = delete;
726 // 20.7.16.2.4, function invocation:
727 _Rp operator()() const;
729 #ifndef _LIBCPP_NO_RTTI
730 // 20.7.16.2.5, function target access:
731 const std::type_info& target_type() const;
732 template <typename _Tp> _Tp* target();
733 template <typename _Tp> const _Tp* target() const;
734 #endif // _LIBCPP_NO_RTTI
738 function<_Rp()>::function(const function& __f)
742 else if (__f.__f_ == (const __base*)&__f.__buf_)
744 __f_ = (__base*)&__buf_;
745 __f.__f_->__clone(__f_);
748 __f_ = __f.__f_->__clone();
752 template<class _Alloc>
753 function<_Rp()>::function(allocator_arg_t, const _Alloc&, const function& __f)
757 else if (__f.__f_ == (const __base*)&__f.__buf_)
759 __f_ = (__base*)&__buf_;
760 __f.__f_->__clone(__f_);
763 __f_ = __f.__f_->__clone();
768 function<_Rp()>::function(_Fp __f,
769 typename enable_if<!is_integral<_Fp>::value>::type*)
774 typedef __function::__func<_Fp, allocator<_Fp>, _Rp()> _FF;
775 if (sizeof(_FF) <= sizeof(__buf_))
777 __f_ = (__base*)&__buf_;
778 ::new (__f_) _FF(__f);
782 typedef allocator<_FF> _Ap;
784 typedef __allocator_destructor<_Ap> _Dp;
785 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
786 ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a));
787 __f_ = __hold.release();
793 template <class _Fp, class _Alloc>
794 function<_Rp()>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
795 typename enable_if<!is_integral<_Fp>::value>::type*)
798 typedef allocator_traits<_Alloc> __alloc_traits;
801 typedef __function::__func<_Fp, _Alloc, _Rp()> _FF;
802 if (sizeof(_FF) <= sizeof(__buf_))
804 __f_ = (__base*)&__buf_;
805 ::new (__f_) _FF(__f, __a0);
809 typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap;
811 typedef __allocator_destructor<_Ap> _Dp;
812 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
813 ::new (__hold.get()) _FF(__f, _Alloc(__a));
814 __f_ = __hold.release();
821 function<_Rp()>::operator=(const function& __f)
823 function(__f).swap(*this);
829 function<_Rp()>::operator=(nullptr_t)
831 if (__f_ == (__base*)&__buf_)
834 __f_->destroy_deallocate();
843 !is_integral<_Fp>::value,
846 function<_Rp()>::operator=(_Fp __f)
848 function(_VSTD::move(__f)).swap(*this);
853 function<_Rp()>::~function()
855 if (__f_ == (__base*)&__buf_)
858 __f_->destroy_deallocate();
863 function<_Rp()>::swap(function& __f)
865 if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
867 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
868 __base* __t = (__base*)&__tempbuf;
872 __f.__f_->__clone((__base*)&__buf_);
875 __f_ = (__base*)&__buf_;
876 __t->__clone((__base*)&__f.__buf_);
878 __f.__f_ = (__base*)&__f.__buf_;
880 else if (__f_ == (__base*)&__buf_)
882 __f_->__clone((__base*)&__f.__buf_);
885 __f.__f_ = (__base*)&__f.__buf_;
887 else if (__f.__f_ == (__base*)&__f.__buf_)
889 __f.__f_->__clone((__base*)&__buf_);
892 __f_ = (__base*)&__buf_;
895 _VSTD::swap(__f_, __f.__f_);
900 function<_Rp()>::operator()() const
902 #ifndef _LIBCPP_NO_EXCEPTIONS
904 throw bad_function_call();
905 #endif // _LIBCPP_NO_EXCEPTIONS
909 #ifndef _LIBCPP_NO_RTTI
912 const std::type_info&
913 function<_Rp()>::target_type() const
917 return __f_->target_type();
921 template <typename _Tp>
923 function<_Rp()>::target()
927 return (_Tp*)__f_->target(typeid(_Tp));
931 template <typename _Tp>
933 function<_Rp()>::target() const
936 return (const _Tp*)0;
937 return (const _Tp*)__f_->target(typeid(_Tp));
940 #endif // _LIBCPP_NO_RTTI
942 template<class _Rp, class _A0>
943 class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_A0)>
944 : public unary_function<_A0, _Rp>
946 typedef __function::__base<_Rp(_A0)> __base;
947 aligned_storage<3*sizeof(void*)>::type __buf_;
951 _LIBCPP_INLINE_VISIBILITY
952 static bool __not_null(const _Fp&) {return true;}
953 template <class _R2, class _B0>
954 _LIBCPP_INLINE_VISIBILITY
955 static bool __not_null(_R2 (*__p)(_B0)) {return __p;}
956 template <class _R2, class _Cp>
957 _LIBCPP_INLINE_VISIBILITY
958 static bool __not_null(_R2 (_Cp::*__p)()) {return __p;}
959 template <class _R2, class _Cp>
960 _LIBCPP_INLINE_VISIBILITY
961 static bool __not_null(_R2 (_Cp::*__p)() const) {return __p;}
962 template <class _R2, class _Cp>
963 _LIBCPP_INLINE_VISIBILITY
964 static bool __not_null(_R2 (_Cp::*__p)() volatile) {return __p;}
965 template <class _R2, class _Cp>
966 _LIBCPP_INLINE_VISIBILITY
967 static bool __not_null(_R2 (_Cp::*__p)() const volatile) {return __p;}
968 template <class _R2, class _B0>
969 _LIBCPP_INLINE_VISIBILITY
970 static bool __not_null(const function<_R2(_B0)>& __p) {return __p;}
972 typedef _Rp result_type;
974 // 20.7.16.2.1, construct/copy/destroy:
975 _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {}
976 _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {}
977 function(const function&);
980 typename enable_if<!is_integral<_Fp>::value>::type* = 0);
982 template<class _Alloc>
983 _LIBCPP_INLINE_VISIBILITY
984 function(allocator_arg_t, const _Alloc&) : __f_(0) {}
985 template<class _Alloc>
986 _LIBCPP_INLINE_VISIBILITY
987 function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {}
988 template<class _Alloc>
989 function(allocator_arg_t, const _Alloc&, const function&);
990 template<class _Fp, class _Alloc>
991 function(allocator_arg_t, const _Alloc& __a, _Fp __f,
992 typename enable_if<!is_integral<_Fp>::value>::type* = 0);
994 function& operator=(const function&);
995 function& operator=(nullptr_t);
999 !is_integral<_Fp>::value,
1006 // 20.7.16.2.2, function modifiers:
1007 void swap(function&);
1008 template<class _Fp, class _Alloc>
1009 _LIBCPP_INLINE_VISIBILITY
1010 void assign(_Fp __f, const _Alloc& __a)
1011 {function(allocator_arg, __a, __f).swap(*this);}
1013 // 20.7.16.2.3, function capacity:
1014 _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;}
1017 // deleted overloads close possible hole in the type system
1018 template<class _R2, class _B0>
1019 bool operator==(const function<_R2(_B0)>&) const;// = delete;
1020 template<class _R2, class _B0>
1021 bool operator!=(const function<_R2(_B0)>&) const;// = delete;
1023 // 20.7.16.2.4, function invocation:
1024 _Rp operator()(_A0) const;
1026 #ifndef _LIBCPP_NO_RTTI
1027 // 20.7.16.2.5, function target access:
1028 const std::type_info& target_type() const;
1029 template <typename _Tp> _Tp* target();
1030 template <typename _Tp> const _Tp* target() const;
1031 #endif // _LIBCPP_NO_RTTI
1034 template<class _Rp, class _A0>
1035 function<_Rp(_A0)>::function(const function& __f)
1039 else if (__f.__f_ == (const __base*)&__f.__buf_)
1041 __f_ = (__base*)&__buf_;
1042 __f.__f_->__clone(__f_);
1045 __f_ = __f.__f_->__clone();
1048 template<class _Rp, class _A0>
1049 template<class _Alloc>
1050 function<_Rp(_A0)>::function(allocator_arg_t, const _Alloc&, const function& __f)
1054 else if (__f.__f_ == (const __base*)&__f.__buf_)
1056 __f_ = (__base*)&__buf_;
1057 __f.__f_->__clone(__f_);
1060 __f_ = __f.__f_->__clone();
1063 template<class _Rp, class _A0>
1064 template <class _Fp>
1065 function<_Rp(_A0)>::function(_Fp __f,
1066 typename enable_if<!is_integral<_Fp>::value>::type*)
1069 if (__not_null(__f))
1071 typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0)> _FF;
1072 if (sizeof(_FF) <= sizeof(__buf_))
1074 __f_ = (__base*)&__buf_;
1075 ::new (__f_) _FF(__f);
1079 typedef allocator<_FF> _Ap;
1081 typedef __allocator_destructor<_Ap> _Dp;
1082 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1083 ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a));
1084 __f_ = __hold.release();
1089 template<class _Rp, class _A0>
1090 template <class _Fp, class _Alloc>
1091 function<_Rp(_A0)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
1092 typename enable_if<!is_integral<_Fp>::value>::type*)
1095 typedef allocator_traits<_Alloc> __alloc_traits;
1096 if (__not_null(__f))
1098 typedef __function::__func<_Fp, _Alloc, _Rp(_A0)> _FF;
1099 if (sizeof(_FF) <= sizeof(__buf_))
1101 __f_ = (__base*)&__buf_;
1102 ::new (__f_) _FF(__f, __a0);
1106 typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap;
1108 typedef __allocator_destructor<_Ap> _Dp;
1109 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1110 ::new (__hold.get()) _FF(__f, _Alloc(__a));
1111 __f_ = __hold.release();
1116 template<class _Rp, class _A0>
1118 function<_Rp(_A0)>::operator=(const function& __f)
1120 function(__f).swap(*this);
1124 template<class _Rp, class _A0>
1126 function<_Rp(_A0)>::operator=(nullptr_t)
1128 if (__f_ == (__base*)&__buf_)
1131 __f_->destroy_deallocate();
1136 template<class _Rp, class _A0>
1137 template <class _Fp>
1140 !is_integral<_Fp>::value,
1143 function<_Rp(_A0)>::operator=(_Fp __f)
1145 function(_VSTD::move(__f)).swap(*this);
1149 template<class _Rp, class _A0>
1150 function<_Rp(_A0)>::~function()
1152 if (__f_ == (__base*)&__buf_)
1155 __f_->destroy_deallocate();
1158 template<class _Rp, class _A0>
1160 function<_Rp(_A0)>::swap(function& __f)
1162 if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
1164 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
1165 __base* __t = (__base*)&__tempbuf;
1169 __f.__f_->__clone((__base*)&__buf_);
1170 __f.__f_->destroy();
1172 __f_ = (__base*)&__buf_;
1173 __t->__clone((__base*)&__f.__buf_);
1175 __f.__f_ = (__base*)&__f.__buf_;
1177 else if (__f_ == (__base*)&__buf_)
1179 __f_->__clone((__base*)&__f.__buf_);
1182 __f.__f_ = (__base*)&__f.__buf_;
1184 else if (__f.__f_ == (__base*)&__f.__buf_)
1186 __f.__f_->__clone((__base*)&__buf_);
1187 __f.__f_->destroy();
1189 __f_ = (__base*)&__buf_;
1192 _VSTD::swap(__f_, __f.__f_);
1195 template<class _Rp, class _A0>
1197 function<_Rp(_A0)>::operator()(_A0 __a0) const
1199 #ifndef _LIBCPP_NO_EXCEPTIONS
1201 throw bad_function_call();
1202 #endif // _LIBCPP_NO_EXCEPTIONS
1203 return (*__f_)(__a0);
1206 #ifndef _LIBCPP_NO_RTTI
1208 template<class _Rp, class _A0>
1209 const std::type_info&
1210 function<_Rp(_A0)>::target_type() const
1213 return typeid(void);
1214 return __f_->target_type();
1217 template<class _Rp, class _A0>
1218 template <typename _Tp>
1220 function<_Rp(_A0)>::target()
1224 return (_Tp*)__f_->target(typeid(_Tp));
1227 template<class _Rp, class _A0>
1228 template <typename _Tp>
1230 function<_Rp(_A0)>::target() const
1233 return (const _Tp*)0;
1234 return (const _Tp*)__f_->target(typeid(_Tp));
1237 #endif // _LIBCPP_NO_RTTI
1239 template<class _Rp, class _A0, class _A1>
1240 class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_A0, _A1)>
1241 : public binary_function<_A0, _A1, _Rp>
1243 typedef __function::__base<_Rp(_A0, _A1)> __base;
1244 aligned_storage<3*sizeof(void*)>::type __buf_;
1247 template <class _Fp>
1248 _LIBCPP_INLINE_VISIBILITY
1249 static bool __not_null(const _Fp&) {return true;}
1250 template <class _R2, class _B0, class _B1>
1251 _LIBCPP_INLINE_VISIBILITY
1252 static bool __not_null(_R2 (*__p)(_B0, _B1)) {return __p;}
1253 template <class _R2, class _Cp, class _B1>
1254 _LIBCPP_INLINE_VISIBILITY
1255 static bool __not_null(_R2 (_Cp::*__p)(_B1)) {return __p;}
1256 template <class _R2, class _Cp, class _B1>
1257 _LIBCPP_INLINE_VISIBILITY
1258 static bool __not_null(_R2 (_Cp::*__p)(_B1) const) {return __p;}
1259 template <class _R2, class _Cp, class _B1>
1260 _LIBCPP_INLINE_VISIBILITY
1261 static bool __not_null(_R2 (_Cp::*__p)(_B1) volatile) {return __p;}
1262 template <class _R2, class _Cp, class _B1>
1263 _LIBCPP_INLINE_VISIBILITY
1264 static bool __not_null(_R2 (_Cp::*__p)(_B1) const volatile) {return __p;}
1265 template <class _R2, class _B0, class _B1>
1266 _LIBCPP_INLINE_VISIBILITY
1267 static bool __not_null(const function<_R2(_B0, _B1)>& __p) {return __p;}
1269 typedef _Rp result_type;
1271 // 20.7.16.2.1, construct/copy/destroy:
1272 _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {}
1273 _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {}
1274 function(const function&);
1277 typename enable_if<!is_integral<_Fp>::value>::type* = 0);
1279 template<class _Alloc>
1280 _LIBCPP_INLINE_VISIBILITY
1281 function(allocator_arg_t, const _Alloc&) : __f_(0) {}
1282 template<class _Alloc>
1283 _LIBCPP_INLINE_VISIBILITY
1284 function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {}
1285 template<class _Alloc>
1286 function(allocator_arg_t, const _Alloc&, const function&);
1287 template<class _Fp, class _Alloc>
1288 function(allocator_arg_t, const _Alloc& __a, _Fp __f,
1289 typename enable_if<!is_integral<_Fp>::value>::type* = 0);
1291 function& operator=(const function&);
1292 function& operator=(nullptr_t);
1296 !is_integral<_Fp>::value,
1303 // 20.7.16.2.2, function modifiers:
1304 void swap(function&);
1305 template<class _Fp, class _Alloc>
1306 _LIBCPP_INLINE_VISIBILITY
1307 void assign(_Fp __f, const _Alloc& __a)
1308 {function(allocator_arg, __a, __f).swap(*this);}
1310 // 20.7.16.2.3, function capacity:
1311 operator bool() const {return __f_;}
1314 // deleted overloads close possible hole in the type system
1315 template<class _R2, class _B0, class _B1>
1316 bool operator==(const function<_R2(_B0, _B1)>&) const;// = delete;
1317 template<class _R2, class _B0, class _B1>
1318 bool operator!=(const function<_R2(_B0, _B1)>&) const;// = delete;
1320 // 20.7.16.2.4, function invocation:
1321 _Rp operator()(_A0, _A1) const;
1323 #ifndef _LIBCPP_NO_RTTI
1324 // 20.7.16.2.5, function target access:
1325 const std::type_info& target_type() const;
1326 template <typename _Tp> _Tp* target();
1327 template <typename _Tp> const _Tp* target() const;
1328 #endif // _LIBCPP_NO_RTTI
1331 template<class _Rp, class _A0, class _A1>
1332 function<_Rp(_A0, _A1)>::function(const function& __f)
1336 else if (__f.__f_ == (const __base*)&__f.__buf_)
1338 __f_ = (__base*)&__buf_;
1339 __f.__f_->__clone(__f_);
1342 __f_ = __f.__f_->__clone();
1345 template<class _Rp, class _A0, class _A1>
1346 template<class _Alloc>
1347 function<_Rp(_A0, _A1)>::function(allocator_arg_t, const _Alloc&, const function& __f)
1351 else if (__f.__f_ == (const __base*)&__f.__buf_)
1353 __f_ = (__base*)&__buf_;
1354 __f.__f_->__clone(__f_);
1357 __f_ = __f.__f_->__clone();
1360 template<class _Rp, class _A0, class _A1>
1361 template <class _Fp>
1362 function<_Rp(_A0, _A1)>::function(_Fp __f,
1363 typename enable_if<!is_integral<_Fp>::value>::type*)
1366 if (__not_null(__f))
1368 typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0, _A1)> _FF;
1369 if (sizeof(_FF) <= sizeof(__buf_))
1371 __f_ = (__base*)&__buf_;
1372 ::new (__f_) _FF(__f);
1376 typedef allocator<_FF> _Ap;
1378 typedef __allocator_destructor<_Ap> _Dp;
1379 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1380 ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a));
1381 __f_ = __hold.release();
1386 template<class _Rp, class _A0, class _A1>
1387 template <class _Fp, class _Alloc>
1388 function<_Rp(_A0, _A1)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
1389 typename enable_if<!is_integral<_Fp>::value>::type*)
1392 typedef allocator_traits<_Alloc> __alloc_traits;
1393 if (__not_null(__f))
1395 typedef __function::__func<_Fp, _Alloc, _Rp(_A0, _A1)> _FF;
1396 if (sizeof(_FF) <= sizeof(__buf_))
1398 __f_ = (__base*)&__buf_;
1399 ::new (__f_) _FF(__f, __a0);
1403 typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap;
1405 typedef __allocator_destructor<_Ap> _Dp;
1406 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1407 ::new (__hold.get()) _FF(__f, _Alloc(__a));
1408 __f_ = __hold.release();
1413 template<class _Rp, class _A0, class _A1>
1414 function<_Rp(_A0, _A1)>&
1415 function<_Rp(_A0, _A1)>::operator=(const function& __f)
1417 function(__f).swap(*this);
1421 template<class _Rp, class _A0, class _A1>
1422 function<_Rp(_A0, _A1)>&
1423 function<_Rp(_A0, _A1)>::operator=(nullptr_t)
1425 if (__f_ == (__base*)&__buf_)
1428 __f_->destroy_deallocate();
1433 template<class _Rp, class _A0, class _A1>
1434 template <class _Fp>
1437 !is_integral<_Fp>::value,
1438 function<_Rp(_A0, _A1)>&
1440 function<_Rp(_A0, _A1)>::operator=(_Fp __f)
1442 function(_VSTD::move(__f)).swap(*this);
1446 template<class _Rp, class _A0, class _A1>
1447 function<_Rp(_A0, _A1)>::~function()
1449 if (__f_ == (__base*)&__buf_)
1452 __f_->destroy_deallocate();
1455 template<class _Rp, class _A0, class _A1>
1457 function<_Rp(_A0, _A1)>::swap(function& __f)
1459 if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
1461 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
1462 __base* __t = (__base*)&__tempbuf;
1466 __f.__f_->__clone((__base*)&__buf_);
1467 __f.__f_->destroy();
1469 __f_ = (__base*)&__buf_;
1470 __t->__clone((__base*)&__f.__buf_);
1472 __f.__f_ = (__base*)&__f.__buf_;
1474 else if (__f_ == (__base*)&__buf_)
1476 __f_->__clone((__base*)&__f.__buf_);
1479 __f.__f_ = (__base*)&__f.__buf_;
1481 else if (__f.__f_ == (__base*)&__f.__buf_)
1483 __f.__f_->__clone((__base*)&__buf_);
1484 __f.__f_->destroy();
1486 __f_ = (__base*)&__buf_;
1489 _VSTD::swap(__f_, __f.__f_);
1492 template<class _Rp, class _A0, class _A1>
1494 function<_Rp(_A0, _A1)>::operator()(_A0 __a0, _A1 __a1) const
1496 #ifndef _LIBCPP_NO_EXCEPTIONS
1498 throw bad_function_call();
1499 #endif // _LIBCPP_NO_EXCEPTIONS
1500 return (*__f_)(__a0, __a1);
1503 #ifndef _LIBCPP_NO_RTTI
1505 template<class _Rp, class _A0, class _A1>
1506 const std::type_info&
1507 function<_Rp(_A0, _A1)>::target_type() const
1510 return typeid(void);
1511 return __f_->target_type();
1514 template<class _Rp, class _A0, class _A1>
1515 template <typename _Tp>
1517 function<_Rp(_A0, _A1)>::target()
1521 return (_Tp*)__f_->target(typeid(_Tp));
1524 template<class _Rp, class _A0, class _A1>
1525 template <typename _Tp>
1527 function<_Rp(_A0, _A1)>::target() const
1530 return (const _Tp*)0;
1531 return (const _Tp*)__f_->target(typeid(_Tp));
1534 #endif // _LIBCPP_NO_RTTI
1536 template<class _Rp, class _A0, class _A1, class _A2>
1537 class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_A0, _A1, _A2)>
1539 typedef __function::__base<_Rp(_A0, _A1, _A2)> __base;
1540 aligned_storage<3*sizeof(void*)>::type __buf_;
1543 template <class _Fp>
1544 _LIBCPP_INLINE_VISIBILITY
1545 static bool __not_null(const _Fp&) {return true;}
1546 template <class _R2, class _B0, class _B1, class _B2>
1547 _LIBCPP_INLINE_VISIBILITY
1548 static bool __not_null(_R2 (*__p)(_B0, _B1, _B2)) {return __p;}
1549 template <class _R2, class _Cp, class _B1, class _B2>
1550 _LIBCPP_INLINE_VISIBILITY
1551 static bool __not_null(_R2 (_Cp::*__p)(_B1, _B2)) {return __p;}
1552 template <class _R2, class _Cp, class _B1, class _B2>
1553 _LIBCPP_INLINE_VISIBILITY
1554 static bool __not_null(_R2 (_Cp::*__p)(_B1, _B2) const) {return __p;}
1555 template <class _R2, class _Cp, class _B1, class _B2>
1556 _LIBCPP_INLINE_VISIBILITY
1557 static bool __not_null(_R2 (_Cp::*__p)(_B1, _B2) volatile) {return __p;}
1558 template <class _R2, class _Cp, class _B1, class _B2>
1559 _LIBCPP_INLINE_VISIBILITY
1560 static bool __not_null(_R2 (_Cp::*__p)(_B1, _B2) const volatile) {return __p;}
1561 template <class _R2, class _B0, class _B1, class _B2>
1562 _LIBCPP_INLINE_VISIBILITY
1563 static bool __not_null(const function<_R2(_B0, _B1, _B2)>& __p) {return __p;}
1565 typedef _Rp result_type;
1567 // 20.7.16.2.1, construct/copy/destroy:
1568 _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {}
1569 _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {}
1570 function(const function&);
1573 typename enable_if<!is_integral<_Fp>::value>::type* = 0);
1575 template<class _Alloc>
1576 _LIBCPP_INLINE_VISIBILITY
1577 function(allocator_arg_t, const _Alloc&) : __f_(0) {}
1578 template<class _Alloc>
1579 _LIBCPP_INLINE_VISIBILITY
1580 function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {}
1581 template<class _Alloc>
1582 function(allocator_arg_t, const _Alloc&, const function&);
1583 template<class _Fp, class _Alloc>
1584 function(allocator_arg_t, const _Alloc& __a, _Fp __f,
1585 typename enable_if<!is_integral<_Fp>::value>::type* = 0);
1587 function& operator=(const function&);
1588 function& operator=(nullptr_t);
1592 !is_integral<_Fp>::value,
1599 // 20.7.16.2.2, function modifiers:
1600 void swap(function&);
1601 template<class _Fp, class _Alloc>
1602 _LIBCPP_INLINE_VISIBILITY
1603 void assign(_Fp __f, const _Alloc& __a)
1604 {function(allocator_arg, __a, __f).swap(*this);}
1606 // 20.7.16.2.3, function capacity:
1607 _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;}
1610 // deleted overloads close possible hole in the type system
1611 template<class _R2, class _B0, class _B1, class _B2>
1612 bool operator==(const function<_R2(_B0, _B1, _B2)>&) const;// = delete;
1613 template<class _R2, class _B0, class _B1, class _B2>
1614 bool operator!=(const function<_R2(_B0, _B1, _B2)>&) const;// = delete;
1616 // 20.7.16.2.4, function invocation:
1617 _Rp operator()(_A0, _A1, _A2) const;
1619 #ifndef _LIBCPP_NO_RTTI
1620 // 20.7.16.2.5, function target access:
1621 const std::type_info& target_type() const;
1622 template <typename _Tp> _Tp* target();
1623 template <typename _Tp> const _Tp* target() const;
1624 #endif // _LIBCPP_NO_RTTI
1627 template<class _Rp, class _A0, class _A1, class _A2>
1628 function<_Rp(_A0, _A1, _A2)>::function(const function& __f)
1632 else if (__f.__f_ == (const __base*)&__f.__buf_)
1634 __f_ = (__base*)&__buf_;
1635 __f.__f_->__clone(__f_);
1638 __f_ = __f.__f_->__clone();
1641 template<class _Rp, class _A0, class _A1, class _A2>
1642 template<class _Alloc>
1643 function<_Rp(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc&,
1644 const function& __f)
1648 else if (__f.__f_ == (const __base*)&__f.__buf_)
1650 __f_ = (__base*)&__buf_;
1651 __f.__f_->__clone(__f_);
1654 __f_ = __f.__f_->__clone();
1657 template<class _Rp, class _A0, class _A1, class _A2>
1658 template <class _Fp>
1659 function<_Rp(_A0, _A1, _A2)>::function(_Fp __f,
1660 typename enable_if<!is_integral<_Fp>::value>::type*)
1663 if (__not_null(__f))
1665 typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0, _A1, _A2)> _FF;
1666 if (sizeof(_FF) <= sizeof(__buf_))
1668 __f_ = (__base*)&__buf_;
1669 ::new (__f_) _FF(__f);
1673 typedef allocator<_FF> _Ap;
1675 typedef __allocator_destructor<_Ap> _Dp;
1676 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1677 ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a));
1678 __f_ = __hold.release();
1683 template<class _Rp, class _A0, class _A1, class _A2>
1684 template <class _Fp, class _Alloc>
1685 function<_Rp(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
1686 typename enable_if<!is_integral<_Fp>::value>::type*)
1689 typedef allocator_traits<_Alloc> __alloc_traits;
1690 if (__not_null(__f))
1692 typedef __function::__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)> _FF;
1693 if (sizeof(_FF) <= sizeof(__buf_))
1695 __f_ = (__base*)&__buf_;
1696 ::new (__f_) _FF(__f, __a0);
1700 typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap;
1702 typedef __allocator_destructor<_Ap> _Dp;
1703 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1704 ::new (__hold.get()) _FF(__f, _Alloc(__a));
1705 __f_ = __hold.release();
1710 template<class _Rp, class _A0, class _A1, class _A2>
1711 function<_Rp(_A0, _A1, _A2)>&
1712 function<_Rp(_A0, _A1, _A2)>::operator=(const function& __f)
1714 function(__f).swap(*this);
1718 template<class _Rp, class _A0, class _A1, class _A2>
1719 function<_Rp(_A0, _A1, _A2)>&
1720 function<_Rp(_A0, _A1, _A2)>::operator=(nullptr_t)
1722 if (__f_ == (__base*)&__buf_)
1725 __f_->destroy_deallocate();
1730 template<class _Rp, class _A0, class _A1, class _A2>
1731 template <class _Fp>
1734 !is_integral<_Fp>::value,
1735 function<_Rp(_A0, _A1, _A2)>&
1737 function<_Rp(_A0, _A1, _A2)>::operator=(_Fp __f)
1739 function(_VSTD::move(__f)).swap(*this);
1743 template<class _Rp, class _A0, class _A1, class _A2>
1744 function<_Rp(_A0, _A1, _A2)>::~function()
1746 if (__f_ == (__base*)&__buf_)
1749 __f_->destroy_deallocate();
1752 template<class _Rp, class _A0, class _A1, class _A2>
1754 function<_Rp(_A0, _A1, _A2)>::swap(function& __f)
1756 if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
1758 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
1759 __base* __t = (__base*)&__tempbuf;
1763 __f.__f_->__clone((__base*)&__buf_);
1764 __f.__f_->destroy();
1766 __f_ = (__base*)&__buf_;
1767 __t->__clone((__base*)&__f.__buf_);
1769 __f.__f_ = (__base*)&__f.__buf_;
1771 else if (__f_ == (__base*)&__buf_)
1773 __f_->__clone((__base*)&__f.__buf_);
1776 __f.__f_ = (__base*)&__f.__buf_;
1778 else if (__f.__f_ == (__base*)&__f.__buf_)
1780 __f.__f_->__clone((__base*)&__buf_);
1781 __f.__f_->destroy();
1783 __f_ = (__base*)&__buf_;
1786 _VSTD::swap(__f_, __f.__f_);
1789 template<class _Rp, class _A0, class _A1, class _A2>
1791 function<_Rp(_A0, _A1, _A2)>::operator()(_A0 __a0, _A1 __a1, _A2 __a2) const
1793 #ifndef _LIBCPP_NO_EXCEPTIONS
1795 throw bad_function_call();
1796 #endif // _LIBCPP_NO_EXCEPTIONS
1797 return (*__f_)(__a0, __a1, __a2);
1800 #ifndef _LIBCPP_NO_RTTI
1802 template<class _Rp, class _A0, class _A1, class _A2>
1803 const std::type_info&
1804 function<_Rp(_A0, _A1, _A2)>::target_type() const
1807 return typeid(void);
1808 return __f_->target_type();
1811 template<class _Rp, class _A0, class _A1, class _A2>
1812 template <typename _Tp>
1814 function<_Rp(_A0, _A1, _A2)>::target()
1818 return (_Tp*)__f_->target(typeid(_Tp));
1821 template<class _Rp, class _A0, class _A1, class _A2>
1822 template <typename _Tp>
1824 function<_Rp(_A0, _A1, _A2)>::target() const
1827 return (const _Tp*)0;
1828 return (const _Tp*)__f_->target(typeid(_Tp));
1831 #endif // _LIBCPP_NO_RTTI
1833 template <class _Fp>
1834 inline _LIBCPP_INLINE_VISIBILITY
1836 operator==(const function<_Fp>& __f, nullptr_t) {return !__f;}
1838 template <class _Fp>
1839 inline _LIBCPP_INLINE_VISIBILITY
1841 operator==(nullptr_t, const function<_Fp>& __f) {return !__f;}
1843 template <class _Fp>
1844 inline _LIBCPP_INLINE_VISIBILITY
1846 operator!=(const function<_Fp>& __f, nullptr_t) {return (bool)__f;}
1848 template <class _Fp>
1849 inline _LIBCPP_INLINE_VISIBILITY
1851 operator!=(nullptr_t, const function<_Fp>& __f) {return (bool)__f;}
1853 template <class _Fp>
1854 inline _LIBCPP_INLINE_VISIBILITY
1856 swap(function<_Fp>& __x, function<_Fp>& __y)
1857 {return __x.swap(__y);}
1859 template<class _Tp> struct __is_bind_expression : public false_type {};
1860 template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_bind_expression
1861 : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
1863 template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
1864 template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_placeholder
1865 : public __is_placeholder<typename remove_cv<_Tp>::type> {};
1867 namespace placeholders
1870 template <int _Np> struct __ph {};
1881 extern __ph<10> _10;
1886 struct __is_placeholder<placeholders::__ph<_Np> >
1887 : public integral_constant<int, _Np> {};
1889 template <class _Tp, class _Uj>
1890 inline _LIBCPP_INLINE_VISIBILITY
1892 __mu(reference_wrapper<_Tp> __t, _Uj&)
1897 template <bool _IsBindExpr, class _Ti, class ..._Uj>
1898 struct __mu_return1 {};
1900 template <class _Ti, class ..._Uj>
1901 struct __mu_return1<true, _Ti, _Uj...>
1903 typedef typename result_of<_Ti(_Uj...)>::type type;
1906 template <class _Ti, class ..._Uj, size_t ..._Indx>
1907 inline _LIBCPP_INLINE_VISIBILITY
1908 typename __mu_return1<true, _Ti, _Uj...>::type
1909 __mu_expand(_Ti& __ti, tuple<_Uj...>&& __uj, __tuple_indices<_Indx...>)
1911 __ti(_VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj))...);
1914 template <class _Ti, class ..._Uj>
1915 inline _LIBCPP_INLINE_VISIBILITY
1918 is_bind_expression<_Ti>::value,
1919 typename __mu_return1<is_bind_expression<_Ti>::value, _Ti, _Uj...>::type
1921 __mu(_Ti& __ti, tuple<_Uj...>& __uj)
1923 typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
1924 return __mu_expand(__ti, __uj, __indices());
1927 template <bool IsPh, class _Ti, class _Uj>
1928 struct __mu_return2 {};
1930 template <class _Ti, class _Uj>
1931 struct __mu_return2<true, _Ti, _Uj>
1933 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
1936 template <class _Ti, class _Uj>
1937 inline _LIBCPP_INLINE_VISIBILITY
1940 0 < is_placeholder<_Ti>::value,
1941 typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
1943 __mu(_Ti&, _Uj& __uj)
1945 const size_t _Indx = is_placeholder<_Ti>::value - 1;
1946 // compiler bug workaround
1947 typename tuple_element<_Indx, _Uj>::type __t = _VSTD::get<_Indx>(__uj);
1949 // return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj));
1952 template <class _Ti, class _Uj>
1953 inline _LIBCPP_INLINE_VISIBILITY
1956 !is_bind_expression<_Ti>::value &&
1957 is_placeholder<_Ti>::value == 0 &&
1958 !__is_reference_wrapper<_Ti>::value,
1961 __mu(_Ti& __ti, _Uj& __uj)
1966 template <class _Ti, bool IsBindEx, bool IsPh, class _TupleUj>
1967 struct ____mu_return;
1969 template <class _Ti, class ..._Uj>
1970 struct ____mu_return<_Ti, true, false, tuple<_Uj...> >
1972 typedef typename result_of<_Ti(_Uj...)>::type type;
1975 template <class _Ti, class _TupleUj>
1976 struct ____mu_return<_Ti, false, true, _TupleUj>
1978 typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
1979 _TupleUj>::type&& type;
1982 template <class _Ti, class _TupleUj>
1983 struct ____mu_return<_Ti, false, false, _TupleUj>
1988 template <class _Ti, class _TupleUj>
1990 : public ____mu_return<_Ti,
1991 is_bind_expression<_Ti>::value,
1992 0 < is_placeholder<_Ti>::value,
1997 template <class _Ti, class _TupleUj>
1998 struct __mu_return<reference_wrapper<_Ti>, _TupleUj>
2003 template <class _Fp, class _BoundArgs, class _TupleUj>
2004 struct __bind_return;
2006 template <class _Fp, class ..._BoundArgs, class _TupleUj>
2007 struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
2009 typedef typename __ref_return
2012 typename __mu_return
2020 template <class _Fp, class ..._BoundArgs, class _TupleUj>
2021 struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
2023 typedef typename __ref_return
2026 typename __mu_return
2034 template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
2035 inline _LIBCPP_INLINE_VISIBILITY
2036 typename __bind_return<_Fp, _BoundArgs, _Args>::type
2037 __apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
2040 return __invoke(__f, __mu(_VSTD::get<_Indx>(__bound_args), __args)...);
2043 template<class _Fp, class ..._BoundArgs>
2047 tuple<_BoundArgs...> __bound_args_;
2049 typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
2051 template <class _Gp, class ..._BA>
2052 explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
2053 : __f_(_VSTD::forward<_Gp>(__f)),
2054 __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
2056 template <class ..._Args>
2057 typename __bind_return<_Fp, tuple<_BoundArgs...>, tuple<_Args&&...> >::type
2058 operator()(_Args&& ...__args)
2060 // compiler bug workaround
2061 return __apply_functor(__f_, __bound_args_, __indices(),
2062 tuple<_Args&&...>(__args...));
2065 template <class ..._Args>
2066 typename __bind_return<_Fp, tuple<_BoundArgs...>, tuple<_Args&&...> >::type
2067 operator()(_Args&& ...__args) const
2069 return __apply_functor(__f_, __bound_args_, __indices(),
2070 tuple<_Args&&...>(__args...));
2074 template<class _Fp, class ..._BoundArgs>
2075 struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
2077 template<class _Rp, class _Fp, class ..._BoundArgs>
2079 : public __bind<_Fp, _BoundArgs...>
2081 typedef __bind<_Fp, _BoundArgs...> base;
2083 typedef _Rp result_type;
2085 template <class _Gp, class ..._BA>
2086 explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
2087 : base(_VSTD::forward<_Gp>(__f),
2088 _VSTD::forward<_BA>(__bound_args)...) {}
2090 template <class ..._Args>
2092 operator()(_Args&& ...__args)
2094 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
2095 return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...);
2098 template <class ..._Args>
2100 operator()(_Args&& ...__args) const
2102 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
2103 return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...);
2107 template<class _Rp, class _Fp, class ..._BoundArgs>
2108 struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
2110 template<class _Fp, class ..._BoundArgs>
2111 inline _LIBCPP_INLINE_VISIBILITY
2112 __bind<typename decay<_Fp>::type, typename decay<_BoundArgs>::type...>
2113 bind(_Fp&& __f, _BoundArgs&&... __bound_args)
2115 typedef __bind<typename decay<_Fp>::type, typename decay<_BoundArgs>::type...> type;
2116 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
2119 template<class _Rp, class _Fp, class ..._BoundArgs>
2120 inline _LIBCPP_INLINE_VISIBILITY
2121 __bind_r<_Rp, typename decay<_Fp>::type, typename decay<_BoundArgs>::type...>
2122 bind(_Fp&& __f, _BoundArgs&&... __bound_args)
2124 typedef __bind_r<_Rp, typename decay<_Fp>::type, typename decay<_BoundArgs>::type...> type;
2125 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
2129 #endif // _LIBCPP_FUNCTIONAL_03