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 typename _Alloc::template rebind<__func>::other _Ap;
337 _Ap __a(__f_.second());
338 typedef __allocator_destructor<_Ap> _Dp;
339 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
340 ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
341 return __hold.release();
344 template<class _Fp, class _Alloc, class _Rp>
346 __func<_Fp, _Alloc, _Rp()>::__clone(__base<_Rp()>* __p) const
348 ::new (__p) __func(__f_.first(), __f_.second());
351 template<class _Fp, class _Alloc, class _Rp>
353 __func<_Fp, _Alloc, _Rp()>::destroy()
355 __f_.~__compressed_pair<_Fp, _Alloc>();
358 template<class _Fp, class _Alloc, class _Rp>
360 __func<_Fp, _Alloc, _Rp()>::destroy_deallocate()
362 typedef typename _Alloc::template rebind<__func>::other _Ap;
363 _Ap __a(__f_.second());
364 __f_.~__compressed_pair<_Fp, _Alloc>();
365 __a.deallocate(this, 1);
368 template<class _Fp, class _Alloc, class _Rp>
370 __func<_Fp, _Alloc, _Rp()>::operator()()
372 return __invoke(__f_.first());
375 #ifndef _LIBCPP_NO_RTTI
377 template<class _Fp, class _Alloc, class _Rp>
379 __func<_Fp, _Alloc, _Rp()>::target(const type_info& __ti) const
381 if (__ti == typeid(_Fp))
382 return &__f_.first();
383 return (const void*)0;
386 template<class _Fp, class _Alloc, class _Rp>
387 const std::type_info&
388 __func<_Fp, _Alloc, _Rp()>::target_type() const
393 #endif // _LIBCPP_NO_RTTI
395 template<class _Fp, class _Alloc, class _Rp, class _A0>
396 class __func<_Fp, _Alloc, _Rp(_A0)>
397 : public __base<_Rp(_A0)>
399 __compressed_pair<_Fp, _Alloc> __f_;
401 _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f) : __f_(_VSTD::move(__f)) {}
402 _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f, _Alloc __a)
403 : __f_(_VSTD::move(__f), _VSTD::move(__a)) {}
404 virtual __base<_Rp(_A0)>* __clone() const;
405 virtual void __clone(__base<_Rp(_A0)>*) const;
406 virtual void destroy();
407 virtual void destroy_deallocate();
408 virtual _Rp operator()(_A0);
409 #ifndef _LIBCPP_NO_RTTI
410 virtual const void* target(const type_info&) const;
411 virtual const std::type_info& target_type() const;
412 #endif // _LIBCPP_NO_RTTI
415 template<class _Fp, class _Alloc, class _Rp, class _A0>
417 __func<_Fp, _Alloc, _Rp(_A0)>::__clone() const
419 typedef typename _Alloc::template rebind<__func>::other _Ap;
420 _Ap __a(__f_.second());
421 typedef __allocator_destructor<_Ap> _Dp;
422 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
423 ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
424 return __hold.release();
427 template<class _Fp, class _Alloc, class _Rp, class _A0>
429 __func<_Fp, _Alloc, _Rp(_A0)>::__clone(__base<_Rp(_A0)>* __p) const
431 ::new (__p) __func(__f_.first(), __f_.second());
434 template<class _Fp, class _Alloc, class _Rp, class _A0>
436 __func<_Fp, _Alloc, _Rp(_A0)>::destroy()
438 __f_.~__compressed_pair<_Fp, _Alloc>();
441 template<class _Fp, class _Alloc, class _Rp, class _A0>
443 __func<_Fp, _Alloc, _Rp(_A0)>::destroy_deallocate()
445 typedef typename _Alloc::template rebind<__func>::other _Ap;
446 _Ap __a(__f_.second());
447 __f_.~__compressed_pair<_Fp, _Alloc>();
448 __a.deallocate(this, 1);
451 template<class _Fp, class _Alloc, class _Rp, class _A0>
453 __func<_Fp, _Alloc, _Rp(_A0)>::operator()(_A0 __a0)
455 return __invoke(__f_.first(), __a0);
458 #ifndef _LIBCPP_NO_RTTI
460 template<class _Fp, class _Alloc, class _Rp, class _A0>
462 __func<_Fp, _Alloc, _Rp(_A0)>::target(const type_info& __ti) const
464 if (__ti == typeid(_Fp))
465 return &__f_.first();
466 return (const void*)0;
469 template<class _Fp, class _Alloc, class _Rp, class _A0>
470 const std::type_info&
471 __func<_Fp, _Alloc, _Rp(_A0)>::target_type() const
476 #endif // _LIBCPP_NO_RTTI
478 template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1>
479 class __func<_Fp, _Alloc, _Rp(_A0, _A1)>
480 : public __base<_Rp(_A0, _A1)>
482 __compressed_pair<_Fp, _Alloc> __f_;
484 _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f) : __f_(_VSTD::move(__f)) {}
485 _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f, _Alloc __a)
486 : __f_(_VSTD::move(__f), _VSTD::move(__a)) {}
487 virtual __base<_Rp(_A0, _A1)>* __clone() const;
488 virtual void __clone(__base<_Rp(_A0, _A1)>*) const;
489 virtual void destroy();
490 virtual void destroy_deallocate();
491 virtual _Rp operator()(_A0, _A1);
492 #ifndef _LIBCPP_NO_RTTI
493 virtual const void* target(const type_info&) const;
494 virtual const std::type_info& target_type() const;
495 #endif // _LIBCPP_NO_RTTI
498 template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1>
499 __base<_Rp(_A0, _A1)>*
500 __func<_Fp, _Alloc, _Rp(_A0, _A1)>::__clone() const
502 typedef typename _Alloc::template rebind<__func>::other _Ap;
503 _Ap __a(__f_.second());
504 typedef __allocator_destructor<_Ap> _Dp;
505 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
506 ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
507 return __hold.release();
510 template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1>
512 __func<_Fp, _Alloc, _Rp(_A0, _A1)>::__clone(__base<_Rp(_A0, _A1)>* __p) const
514 ::new (__p) __func(__f_.first(), __f_.second());
517 template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1>
519 __func<_Fp, _Alloc, _Rp(_A0, _A1)>::destroy()
521 __f_.~__compressed_pair<_Fp, _Alloc>();
524 template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1>
526 __func<_Fp, _Alloc, _Rp(_A0, _A1)>::destroy_deallocate()
528 typedef typename _Alloc::template rebind<__func>::other _Ap;
529 _Ap __a(__f_.second());
530 __f_.~__compressed_pair<_Fp, _Alloc>();
531 __a.deallocate(this, 1);
534 template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1>
536 __func<_Fp, _Alloc, _Rp(_A0, _A1)>::operator()(_A0 __a0, _A1 __a1)
538 return __invoke(__f_.first(), __a0, __a1);
541 #ifndef _LIBCPP_NO_RTTI
543 template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1>
545 __func<_Fp, _Alloc, _Rp(_A0, _A1)>::target(const type_info& __ti) const
547 if (__ti == typeid(_Fp))
548 return &__f_.first();
549 return (const void*)0;
552 template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1>
553 const std::type_info&
554 __func<_Fp, _Alloc, _Rp(_A0, _A1)>::target_type() const
559 #endif // _LIBCPP_NO_RTTI
561 template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2>
562 class __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>
563 : public __base<_Rp(_A0, _A1, _A2)>
565 __compressed_pair<_Fp, _Alloc> __f_;
567 _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f) : __f_(_VSTD::move(__f)) {}
568 _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f, _Alloc __a)
569 : __f_(_VSTD::move(__f), _VSTD::move(__a)) {}
570 virtual __base<_Rp(_A0, _A1, _A2)>* __clone() const;
571 virtual void __clone(__base<_Rp(_A0, _A1, _A2)>*) const;
572 virtual void destroy();
573 virtual void destroy_deallocate();
574 virtual _Rp operator()(_A0, _A1, _A2);
575 #ifndef _LIBCPP_NO_RTTI
576 virtual const void* target(const type_info&) const;
577 virtual const std::type_info& target_type() const;
578 #endif // _LIBCPP_NO_RTTI
581 template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2>
582 __base<_Rp(_A0, _A1, _A2)>*
583 __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::__clone() const
585 typedef typename _Alloc::template rebind<__func>::other _Ap;
586 _Ap __a(__f_.second());
587 typedef __allocator_destructor<_Ap> _Dp;
588 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
589 ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
590 return __hold.release();
593 template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2>
595 __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::__clone(__base<_Rp(_A0, _A1, _A2)>* __p) const
597 ::new (__p) __func(__f_.first(), __f_.second());
600 template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2>
602 __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::destroy()
604 __f_.~__compressed_pair<_Fp, _Alloc>();
607 template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2>
609 __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::destroy_deallocate()
611 typedef typename _Alloc::template rebind<__func>::other _Ap;
612 _Ap __a(__f_.second());
613 __f_.~__compressed_pair<_Fp, _Alloc>();
614 __a.deallocate(this, 1);
617 template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2>
619 __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::operator()(_A0 __a0, _A1 __a1, _A2 __a2)
621 return __invoke(__f_.first(), __a0, __a1, __a2);
624 #ifndef _LIBCPP_NO_RTTI
626 template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2>
628 __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::target(const type_info& __ti) const
630 if (__ti == typeid(_Fp))
631 return &__f_.first();
632 return (const void*)0;
635 template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2>
636 const std::type_info&
637 __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::target_type() const
642 #endif // _LIBCPP_NO_RTTI
647 class _LIBCPP_TYPE_VIS_ONLY function<_Rp()>
649 typedef __function::__base<_Rp()> __base;
650 aligned_storage<3*sizeof(void*)>::type __buf_;
654 _LIBCPP_INLINE_VISIBILITY
655 static bool __not_null(const _Fp&) {return true;}
657 _LIBCPP_INLINE_VISIBILITY
658 static bool __not_null(_R2 (*__p)()) {return __p;}
660 _LIBCPP_INLINE_VISIBILITY
661 static bool __not_null(const function<_R2()>& __p) {return __p;}
663 typedef _Rp result_type;
665 // 20.7.16.2.1, construct/copy/destroy:
666 _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {}
667 _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {}
668 function(const function&);
671 typename enable_if<!is_integral<_Fp>::value>::type* = 0);
673 template<class _Alloc>
674 _LIBCPP_INLINE_VISIBILITY
675 function(allocator_arg_t, const _Alloc&) : __f_(0) {}
676 template<class _Alloc>
677 _LIBCPP_INLINE_VISIBILITY
678 function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {}
679 template<class _Alloc>
680 function(allocator_arg_t, const _Alloc&, const function&);
681 template<class _Fp, class _Alloc>
682 function(allocator_arg_t, const _Alloc& __a, _Fp __f,
683 typename enable_if<!is_integral<_Fp>::value>::type* = 0);
685 function& operator=(const function&);
686 function& operator=(nullptr_t);
690 !is_integral<_Fp>::value,
697 // 20.7.16.2.2, function modifiers:
698 void swap(function&);
699 template<class _Fp, class _Alloc>
700 _LIBCPP_INLINE_VISIBILITY
701 void assign(_Fp __f, const _Alloc& __a)
702 {function(allocator_arg, __a, __f).swap(*this);}
704 // 20.7.16.2.3, function capacity:
705 _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;}
708 // deleted overloads close possible hole in the type system
710 bool operator==(const function<_R2()>&) const;// = delete;
712 bool operator!=(const function<_R2()>&) const;// = delete;
714 // 20.7.16.2.4, function invocation:
715 _Rp operator()() const;
717 #ifndef _LIBCPP_NO_RTTI
718 // 20.7.16.2.5, function target access:
719 const std::type_info& target_type() const;
720 template <typename _Tp> _Tp* target();
721 template <typename _Tp> const _Tp* target() const;
722 #endif // _LIBCPP_NO_RTTI
726 function<_Rp()>::function(const function& __f)
730 else if (__f.__f_ == (const __base*)&__f.__buf_)
732 __f_ = (__base*)&__buf_;
733 __f.__f_->__clone(__f_);
736 __f_ = __f.__f_->__clone();
740 template<class _Alloc>
741 function<_Rp()>::function(allocator_arg_t, const _Alloc&, const function& __f)
745 else if (__f.__f_ == (const __base*)&__f.__buf_)
747 __f_ = (__base*)&__buf_;
748 __f.__f_->__clone(__f_);
751 __f_ = __f.__f_->__clone();
756 function<_Rp()>::function(_Fp __f,
757 typename enable_if<!is_integral<_Fp>::value>::type*)
762 typedef __function::__func<_Fp, allocator<_Fp>, _Rp()> _FF;
763 if (sizeof(_FF) <= sizeof(__buf_))
765 __f_ = (__base*)&__buf_;
766 ::new (__f_) _FF(__f);
770 typedef allocator<_FF> _Ap;
772 typedef __allocator_destructor<_Ap> _Dp;
773 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
774 ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a));
775 __f_ = __hold.release();
781 template <class _Fp, class _Alloc>
782 function<_Rp()>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
783 typename enable_if<!is_integral<_Fp>::value>::type*)
786 typedef allocator_traits<_Alloc> __alloc_traits;
789 typedef __function::__func<_Fp, _Alloc, _Rp()> _FF;
790 if (sizeof(_FF) <= sizeof(__buf_))
792 __f_ = (__base*)&__buf_;
793 ::new (__f_) _FF(__f);
797 typedef typename __alloc_traits::template
798 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
801 rebind_alloc<_FF>::other
805 typedef __allocator_destructor<_Ap> _Dp;
806 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
807 ::new (__hold.get()) _FF(__f, _Alloc(__a));
808 __f_ = __hold.release();
815 function<_Rp()>::operator=(const function& __f)
817 function(__f).swap(*this);
823 function<_Rp()>::operator=(nullptr_t)
825 if (__f_ == (__base*)&__buf_)
828 __f_->destroy_deallocate();
836 !is_integral<_Fp>::value,
839 function<_Rp()>::operator=(_Fp __f)
841 function(_VSTD::move(__f)).swap(*this);
846 function<_Rp()>::~function()
848 if (__f_ == (__base*)&__buf_)
851 __f_->destroy_deallocate();
856 function<_Rp()>::swap(function& __f)
858 if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
860 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
861 __base* __t = (__base*)&__tempbuf;
865 __f.__f_->__clone((__base*)&__buf_);
868 __f_ = (__base*)&__buf_;
869 __t->__clone((__base*)&__f.__buf_);
871 __f.__f_ = (__base*)&__f.__buf_;
873 else if (__f_ == (__base*)&__buf_)
875 __f_->__clone((__base*)&__f.__buf_);
878 __f.__f_ = (__base*)&__f.__buf_;
880 else if (__f.__f_ == (__base*)&__f.__buf_)
882 __f.__f_->__clone((__base*)&__buf_);
885 __f_ = (__base*)&__buf_;
888 _VSTD::swap(__f_, __f.__f_);
893 function<_Rp()>::operator()() const
895 #ifndef _LIBCPP_NO_EXCEPTIONS
897 throw bad_function_call();
898 #endif // _LIBCPP_NO_EXCEPTIONS
902 #ifndef _LIBCPP_NO_RTTI
905 const std::type_info&
906 function<_Rp()>::target_type() const
910 return __f_->target_type();
914 template <typename _Tp>
916 function<_Rp()>::target()
920 return (_Tp*)__f_->target(typeid(_Tp));
924 template <typename _Tp>
926 function<_Rp()>::target() const
929 return (const _Tp*)0;
930 return (const _Tp*)__f_->target(typeid(_Tp));
933 #endif // _LIBCPP_NO_RTTI
935 template<class _Rp, class _A0>
936 class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_A0)>
937 : public unary_function<_A0, _Rp>
939 typedef __function::__base<_Rp(_A0)> __base;
940 aligned_storage<3*sizeof(void*)>::type __buf_;
944 _LIBCPP_INLINE_VISIBILITY
945 static bool __not_null(const _Fp&) {return true;}
946 template <class _R2, class _B0>
947 _LIBCPP_INLINE_VISIBILITY
948 static bool __not_null(_R2 (*__p)(_B0)) {return __p;}
949 template <class _R2, class _Cp>
950 _LIBCPP_INLINE_VISIBILITY
951 static bool __not_null(_R2 (_Cp::*__p)()) {return __p;}
952 template <class _R2, class _Cp>
953 _LIBCPP_INLINE_VISIBILITY
954 static bool __not_null(_R2 (_Cp::*__p)() const) {return __p;}
955 template <class _R2, class _Cp>
956 _LIBCPP_INLINE_VISIBILITY
957 static bool __not_null(_R2 (_Cp::*__p)() volatile) {return __p;}
958 template <class _R2, class _Cp>
959 _LIBCPP_INLINE_VISIBILITY
960 static bool __not_null(_R2 (_Cp::*__p)() const volatile) {return __p;}
961 template <class _R2, class _B0>
962 _LIBCPP_INLINE_VISIBILITY
963 static bool __not_null(const function<_R2(_B0)>& __p) {return __p;}
965 typedef _Rp result_type;
967 // 20.7.16.2.1, construct/copy/destroy:
968 _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {}
969 _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {}
970 function(const function&);
973 typename enable_if<!is_integral<_Fp>::value>::type* = 0);
975 template<class _Alloc>
976 _LIBCPP_INLINE_VISIBILITY
977 function(allocator_arg_t, const _Alloc&) : __f_(0) {}
978 template<class _Alloc>
979 _LIBCPP_INLINE_VISIBILITY
980 function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {}
981 template<class _Alloc>
982 function(allocator_arg_t, const _Alloc&, const function&);
983 template<class _Fp, class _Alloc>
984 function(allocator_arg_t, const _Alloc& __a, _Fp __f,
985 typename enable_if<!is_integral<_Fp>::value>::type* = 0);
987 function& operator=(const function&);
988 function& operator=(nullptr_t);
992 !is_integral<_Fp>::value,
999 // 20.7.16.2.2, function modifiers:
1000 void swap(function&);
1001 template<class _Fp, class _Alloc>
1002 _LIBCPP_INLINE_VISIBILITY
1003 void assign(_Fp __f, const _Alloc& __a)
1004 {function(allocator_arg, __a, __f).swap(*this);}
1006 // 20.7.16.2.3, function capacity:
1007 _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;}
1010 // deleted overloads close possible hole in the type system
1011 template<class _R2, class _B0>
1012 bool operator==(const function<_R2(_B0)>&) const;// = delete;
1013 template<class _R2, class _B0>
1014 bool operator!=(const function<_R2(_B0)>&) const;// = delete;
1016 // 20.7.16.2.4, function invocation:
1017 _Rp operator()(_A0) const;
1019 #ifndef _LIBCPP_NO_RTTI
1020 // 20.7.16.2.5, function target access:
1021 const std::type_info& target_type() const;
1022 template <typename _Tp> _Tp* target();
1023 template <typename _Tp> const _Tp* target() const;
1024 #endif // _LIBCPP_NO_RTTI
1027 template<class _Rp, class _A0>
1028 function<_Rp(_A0)>::function(const function& __f)
1032 else if (__f.__f_ == (const __base*)&__f.__buf_)
1034 __f_ = (__base*)&__buf_;
1035 __f.__f_->__clone(__f_);
1038 __f_ = __f.__f_->__clone();
1041 template<class _Rp, class _A0>
1042 template<class _Alloc>
1043 function<_Rp(_A0)>::function(allocator_arg_t, const _Alloc&, const function& __f)
1047 else if (__f.__f_ == (const __base*)&__f.__buf_)
1049 __f_ = (__base*)&__buf_;
1050 __f.__f_->__clone(__f_);
1053 __f_ = __f.__f_->__clone();
1056 template<class _Rp, class _A0>
1057 template <class _Fp>
1058 function<_Rp(_A0)>::function(_Fp __f,
1059 typename enable_if<!is_integral<_Fp>::value>::type*)
1062 if (__not_null(__f))
1064 typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0)> _FF;
1065 if (sizeof(_FF) <= sizeof(__buf_))
1067 __f_ = (__base*)&__buf_;
1068 ::new (__f_) _FF(__f);
1072 typedef allocator<_FF> _Ap;
1074 typedef __allocator_destructor<_Ap> _Dp;
1075 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1076 ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a));
1077 __f_ = __hold.release();
1082 template<class _Rp, class _A0>
1083 template <class _Fp, class _Alloc>
1084 function<_Rp(_A0)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
1085 typename enable_if<!is_integral<_Fp>::value>::type*)
1088 typedef allocator_traits<_Alloc> __alloc_traits;
1089 if (__not_null(__f))
1091 typedef __function::__func<_Fp, _Alloc, _Rp(_A0)> _FF;
1092 if (sizeof(_FF) <= sizeof(__buf_))
1094 __f_ = (__base*)&__buf_;
1095 ::new (__f_) _FF(__f);
1099 typedef typename __alloc_traits::template
1100 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1103 rebind_alloc<_FF>::other
1107 typedef __allocator_destructor<_Ap> _Dp;
1108 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1109 ::new (__hold.get()) _FF(__f, _Alloc(__a));
1110 __f_ = __hold.release();
1115 template<class _Rp, class _A0>
1117 function<_Rp(_A0)>::operator=(const function& __f)
1119 function(__f).swap(*this);
1123 template<class _Rp, class _A0>
1125 function<_Rp(_A0)>::operator=(nullptr_t)
1127 if (__f_ == (__base*)&__buf_)
1130 __f_->destroy_deallocate();
1134 template<class _Rp, class _A0>
1135 template <class _Fp>
1138 !is_integral<_Fp>::value,
1141 function<_Rp(_A0)>::operator=(_Fp __f)
1143 function(_VSTD::move(__f)).swap(*this);
1147 template<class _Rp, class _A0>
1148 function<_Rp(_A0)>::~function()
1150 if (__f_ == (__base*)&__buf_)
1153 __f_->destroy_deallocate();
1156 template<class _Rp, class _A0>
1158 function<_Rp(_A0)>::swap(function& __f)
1160 if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
1162 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
1163 __base* __t = (__base*)&__tempbuf;
1167 __f.__f_->__clone((__base*)&__buf_);
1168 __f.__f_->destroy();
1170 __f_ = (__base*)&__buf_;
1171 __t->__clone((__base*)&__f.__buf_);
1173 __f.__f_ = (__base*)&__f.__buf_;
1175 else if (__f_ == (__base*)&__buf_)
1177 __f_->__clone((__base*)&__f.__buf_);
1180 __f.__f_ = (__base*)&__f.__buf_;
1182 else if (__f.__f_ == (__base*)&__f.__buf_)
1184 __f.__f_->__clone((__base*)&__buf_);
1185 __f.__f_->destroy();
1187 __f_ = (__base*)&__buf_;
1190 _VSTD::swap(__f_, __f.__f_);
1193 template<class _Rp, class _A0>
1195 function<_Rp(_A0)>::operator()(_A0 __a0) const
1197 #ifndef _LIBCPP_NO_EXCEPTIONS
1199 throw bad_function_call();
1200 #endif // _LIBCPP_NO_EXCEPTIONS
1201 return (*__f_)(__a0);
1204 #ifndef _LIBCPP_NO_RTTI
1206 template<class _Rp, class _A0>
1207 const std::type_info&
1208 function<_Rp(_A0)>::target_type() const
1211 return typeid(void);
1212 return __f_->target_type();
1215 template<class _Rp, class _A0>
1216 template <typename _Tp>
1218 function<_Rp(_A0)>::target()
1222 return (_Tp*)__f_->target(typeid(_Tp));
1225 template<class _Rp, class _A0>
1226 template <typename _Tp>
1228 function<_Rp(_A0)>::target() const
1231 return (const _Tp*)0;
1232 return (const _Tp*)__f_->target(typeid(_Tp));
1235 #endif // _LIBCPP_NO_RTTI
1237 template<class _Rp, class _A0, class _A1>
1238 class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_A0, _A1)>
1239 : public binary_function<_A0, _A1, _Rp>
1241 typedef __function::__base<_Rp(_A0, _A1)> __base;
1242 aligned_storage<3*sizeof(void*)>::type __buf_;
1245 template <class _Fp>
1246 _LIBCPP_INLINE_VISIBILITY
1247 static bool __not_null(const _Fp&) {return true;}
1248 template <class _R2, class _B0, class _B1>
1249 _LIBCPP_INLINE_VISIBILITY
1250 static bool __not_null(_R2 (*__p)(_B0, _B1)) {return __p;}
1251 template <class _R2, class _Cp, class _B1>
1252 _LIBCPP_INLINE_VISIBILITY
1253 static bool __not_null(_R2 (_Cp::*__p)(_B1)) {return __p;}
1254 template <class _R2, class _Cp, class _B1>
1255 _LIBCPP_INLINE_VISIBILITY
1256 static bool __not_null(_R2 (_Cp::*__p)(_B1) const) {return __p;}
1257 template <class _R2, class _Cp, class _B1>
1258 _LIBCPP_INLINE_VISIBILITY
1259 static bool __not_null(_R2 (_Cp::*__p)(_B1) volatile) {return __p;}
1260 template <class _R2, class _Cp, class _B1>
1261 _LIBCPP_INLINE_VISIBILITY
1262 static bool __not_null(_R2 (_Cp::*__p)(_B1) const volatile) {return __p;}
1263 template <class _R2, class _B0, class _B1>
1264 _LIBCPP_INLINE_VISIBILITY
1265 static bool __not_null(const function<_R2(_B0, _B1)>& __p) {return __p;}
1267 typedef _Rp result_type;
1269 // 20.7.16.2.1, construct/copy/destroy:
1270 _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {}
1271 _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {}
1272 function(const function&);
1275 typename enable_if<!is_integral<_Fp>::value>::type* = 0);
1277 template<class _Alloc>
1278 _LIBCPP_INLINE_VISIBILITY
1279 function(allocator_arg_t, const _Alloc&) : __f_(0) {}
1280 template<class _Alloc>
1281 _LIBCPP_INLINE_VISIBILITY
1282 function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {}
1283 template<class _Alloc>
1284 function(allocator_arg_t, const _Alloc&, const function&);
1285 template<class _Fp, class _Alloc>
1286 function(allocator_arg_t, const _Alloc& __a, _Fp __f,
1287 typename enable_if<!is_integral<_Fp>::value>::type* = 0);
1289 function& operator=(const function&);
1290 function& operator=(nullptr_t);
1294 !is_integral<_Fp>::value,
1301 // 20.7.16.2.2, function modifiers:
1302 void swap(function&);
1303 template<class _Fp, class _Alloc>
1304 _LIBCPP_INLINE_VISIBILITY
1305 void assign(_Fp __f, const _Alloc& __a)
1306 {function(allocator_arg, __a, __f).swap(*this);}
1308 // 20.7.16.2.3, function capacity:
1309 operator bool() const {return __f_;}
1312 // deleted overloads close possible hole in the type system
1313 template<class _R2, class _B0, class _B1>
1314 bool operator==(const function<_R2(_B0, _B1)>&) const;// = delete;
1315 template<class _R2, class _B0, class _B1>
1316 bool operator!=(const function<_R2(_B0, _B1)>&) const;// = delete;
1318 // 20.7.16.2.4, function invocation:
1319 _Rp operator()(_A0, _A1) const;
1321 #ifndef _LIBCPP_NO_RTTI
1322 // 20.7.16.2.5, function target access:
1323 const std::type_info& target_type() const;
1324 template <typename _Tp> _Tp* target();
1325 template <typename _Tp> const _Tp* target() const;
1326 #endif // _LIBCPP_NO_RTTI
1329 template<class _Rp, class _A0, class _A1>
1330 function<_Rp(_A0, _A1)>::function(const function& __f)
1334 else if (__f.__f_ == (const __base*)&__f.__buf_)
1336 __f_ = (__base*)&__buf_;
1337 __f.__f_->__clone(__f_);
1340 __f_ = __f.__f_->__clone();
1343 template<class _Rp, class _A0, class _A1>
1344 template<class _Alloc>
1345 function<_Rp(_A0, _A1)>::function(allocator_arg_t, const _Alloc&, const function& __f)
1349 else if (__f.__f_ == (const __base*)&__f.__buf_)
1351 __f_ = (__base*)&__buf_;
1352 __f.__f_->__clone(__f_);
1355 __f_ = __f.__f_->__clone();
1358 template<class _Rp, class _A0, class _A1>
1359 template <class _Fp>
1360 function<_Rp(_A0, _A1)>::function(_Fp __f,
1361 typename enable_if<!is_integral<_Fp>::value>::type*)
1364 if (__not_null(__f))
1366 typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0, _A1)> _FF;
1367 if (sizeof(_FF) <= sizeof(__buf_))
1369 __f_ = (__base*)&__buf_;
1370 ::new (__f_) _FF(__f);
1374 typedef allocator<_FF> _Ap;
1376 typedef __allocator_destructor<_Ap> _Dp;
1377 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1378 ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a));
1379 __f_ = __hold.release();
1384 template<class _Rp, class _A0, class _A1>
1385 template <class _Fp, class _Alloc>
1386 function<_Rp(_A0, _A1)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
1387 typename enable_if<!is_integral<_Fp>::value>::type*)
1390 typedef allocator_traits<_Alloc> __alloc_traits;
1391 if (__not_null(__f))
1393 typedef __function::__func<_Fp, _Alloc, _Rp(_A0, _A1)> _FF;
1394 if (sizeof(_FF) <= sizeof(__buf_))
1396 __f_ = (__base*)&__buf_;
1397 ::new (__f_) _FF(__f);
1401 typedef typename __alloc_traits::template
1402 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1405 rebind_alloc<_FF>::other
1409 typedef __allocator_destructor<_Ap> _Dp;
1410 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1411 ::new (__hold.get()) _FF(__f, _Alloc(__a));
1412 __f_ = __hold.release();
1417 template<class _Rp, class _A0, class _A1>
1418 function<_Rp(_A0, _A1)>&
1419 function<_Rp(_A0, _A1)>::operator=(const function& __f)
1421 function(__f).swap(*this);
1425 template<class _Rp, class _A0, class _A1>
1426 function<_Rp(_A0, _A1)>&
1427 function<_Rp(_A0, _A1)>::operator=(nullptr_t)
1429 if (__f_ == (__base*)&__buf_)
1432 __f_->destroy_deallocate();
1436 template<class _Rp, class _A0, class _A1>
1437 template <class _Fp>
1440 !is_integral<_Fp>::value,
1441 function<_Rp(_A0, _A1)>&
1443 function<_Rp(_A0, _A1)>::operator=(_Fp __f)
1445 function(_VSTD::move(__f)).swap(*this);
1449 template<class _Rp, class _A0, class _A1>
1450 function<_Rp(_A0, _A1)>::~function()
1452 if (__f_ == (__base*)&__buf_)
1455 __f_->destroy_deallocate();
1458 template<class _Rp, class _A0, class _A1>
1460 function<_Rp(_A0, _A1)>::swap(function& __f)
1462 if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
1464 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
1465 __base* __t = (__base*)&__tempbuf;
1469 __f.__f_->__clone((__base*)&__buf_);
1470 __f.__f_->destroy();
1472 __f_ = (__base*)&__buf_;
1473 __t->__clone((__base*)&__f.__buf_);
1475 __f.__f_ = (__base*)&__f.__buf_;
1477 else if (__f_ == (__base*)&__buf_)
1479 __f_->__clone((__base*)&__f.__buf_);
1482 __f.__f_ = (__base*)&__f.__buf_;
1484 else if (__f.__f_ == (__base*)&__f.__buf_)
1486 __f.__f_->__clone((__base*)&__buf_);
1487 __f.__f_->destroy();
1489 __f_ = (__base*)&__buf_;
1492 _VSTD::swap(__f_, __f.__f_);
1495 template<class _Rp, class _A0, class _A1>
1497 function<_Rp(_A0, _A1)>::operator()(_A0 __a0, _A1 __a1) const
1499 #ifndef _LIBCPP_NO_EXCEPTIONS
1501 throw bad_function_call();
1502 #endif // _LIBCPP_NO_EXCEPTIONS
1503 return (*__f_)(__a0, __a1);
1506 #ifndef _LIBCPP_NO_RTTI
1508 template<class _Rp, class _A0, class _A1>
1509 const std::type_info&
1510 function<_Rp(_A0, _A1)>::target_type() const
1513 return typeid(void);
1514 return __f_->target_type();
1517 template<class _Rp, class _A0, class _A1>
1518 template <typename _Tp>
1520 function<_Rp(_A0, _A1)>::target()
1524 return (_Tp*)__f_->target(typeid(_Tp));
1527 template<class _Rp, class _A0, class _A1>
1528 template <typename _Tp>
1530 function<_Rp(_A0, _A1)>::target() const
1533 return (const _Tp*)0;
1534 return (const _Tp*)__f_->target(typeid(_Tp));
1537 #endif // _LIBCPP_NO_RTTI
1539 template<class _Rp, class _A0, class _A1, class _A2>
1540 class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_A0, _A1, _A2)>
1542 typedef __function::__base<_Rp(_A0, _A1, _A2)> __base;
1543 aligned_storage<3*sizeof(void*)>::type __buf_;
1546 template <class _Fp>
1547 _LIBCPP_INLINE_VISIBILITY
1548 static bool __not_null(const _Fp&) {return true;}
1549 template <class _R2, class _B0, class _B1, class _B2>
1550 _LIBCPP_INLINE_VISIBILITY
1551 static bool __not_null(_R2 (*__p)(_B0, _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)) {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) const) {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) volatile) {return __p;}
1561 template <class _R2, class _Cp, class _B1, class _B2>
1562 _LIBCPP_INLINE_VISIBILITY
1563 static bool __not_null(_R2 (_Cp::*__p)(_B1, _B2) const volatile) {return __p;}
1564 template <class _R2, class _B0, class _B1, class _B2>
1565 _LIBCPP_INLINE_VISIBILITY
1566 static bool __not_null(const function<_R2(_B0, _B1, _B2)>& __p) {return __p;}
1568 typedef _Rp result_type;
1570 // 20.7.16.2.1, construct/copy/destroy:
1571 _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {}
1572 _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {}
1573 function(const function&);
1576 typename enable_if<!is_integral<_Fp>::value>::type* = 0);
1578 template<class _Alloc>
1579 _LIBCPP_INLINE_VISIBILITY
1580 function(allocator_arg_t, const _Alloc&) : __f_(0) {}
1581 template<class _Alloc>
1582 _LIBCPP_INLINE_VISIBILITY
1583 function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {}
1584 template<class _Alloc>
1585 function(allocator_arg_t, const _Alloc&, const function&);
1586 template<class _Fp, class _Alloc>
1587 function(allocator_arg_t, const _Alloc& __a, _Fp __f,
1588 typename enable_if<!is_integral<_Fp>::value>::type* = 0);
1590 function& operator=(const function&);
1591 function& operator=(nullptr_t);
1595 !is_integral<_Fp>::value,
1602 // 20.7.16.2.2, function modifiers:
1603 void swap(function&);
1604 template<class _Fp, class _Alloc>
1605 _LIBCPP_INLINE_VISIBILITY
1606 void assign(_Fp __f, const _Alloc& __a)
1607 {function(allocator_arg, __a, __f).swap(*this);}
1609 // 20.7.16.2.3, function capacity:
1610 _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;}
1613 // deleted overloads close possible hole in the type system
1614 template<class _R2, class _B0, class _B1, class _B2>
1615 bool operator==(const function<_R2(_B0, _B1, _B2)>&) const;// = delete;
1616 template<class _R2, class _B0, class _B1, class _B2>
1617 bool operator!=(const function<_R2(_B0, _B1, _B2)>&) const;// = delete;
1619 // 20.7.16.2.4, function invocation:
1620 _Rp operator()(_A0, _A1, _A2) const;
1622 #ifndef _LIBCPP_NO_RTTI
1623 // 20.7.16.2.5, function target access:
1624 const std::type_info& target_type() const;
1625 template <typename _Tp> _Tp* target();
1626 template <typename _Tp> const _Tp* target() const;
1627 #endif // _LIBCPP_NO_RTTI
1630 template<class _Rp, class _A0, class _A1, class _A2>
1631 function<_Rp(_A0, _A1, _A2)>::function(const function& __f)
1635 else if (__f.__f_ == (const __base*)&__f.__buf_)
1637 __f_ = (__base*)&__buf_;
1638 __f.__f_->__clone(__f_);
1641 __f_ = __f.__f_->__clone();
1644 template<class _Rp, class _A0, class _A1, class _A2>
1645 template<class _Alloc>
1646 function<_Rp(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc&,
1647 const function& __f)
1651 else if (__f.__f_ == (const __base*)&__f.__buf_)
1653 __f_ = (__base*)&__buf_;
1654 __f.__f_->__clone(__f_);
1657 __f_ = __f.__f_->__clone();
1660 template<class _Rp, class _A0, class _A1, class _A2>
1661 template <class _Fp>
1662 function<_Rp(_A0, _A1, _A2)>::function(_Fp __f,
1663 typename enable_if<!is_integral<_Fp>::value>::type*)
1666 if (__not_null(__f))
1668 typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0, _A1, _A2)> _FF;
1669 if (sizeof(_FF) <= sizeof(__buf_))
1671 __f_ = (__base*)&__buf_;
1672 ::new (__f_) _FF(__f);
1676 typedef allocator<_FF> _Ap;
1678 typedef __allocator_destructor<_Ap> _Dp;
1679 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1680 ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a));
1681 __f_ = __hold.release();
1686 template<class _Rp, class _A0, class _A1, class _A2>
1687 template <class _Fp, class _Alloc>
1688 function<_Rp(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
1689 typename enable_if<!is_integral<_Fp>::value>::type*)
1692 typedef allocator_traits<_Alloc> __alloc_traits;
1693 if (__not_null(__f))
1695 typedef __function::__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)> _FF;
1696 if (sizeof(_FF) <= sizeof(__buf_))
1698 __f_ = (__base*)&__buf_;
1699 ::new (__f_) _FF(__f);
1703 typedef typename __alloc_traits::template
1704 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1707 rebind_alloc<_FF>::other
1711 typedef __allocator_destructor<_Ap> _Dp;
1712 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1713 ::new (__hold.get()) _FF(__f, _Alloc(__a));
1714 __f_ = __hold.release();
1719 template<class _Rp, class _A0, class _A1, class _A2>
1720 function<_Rp(_A0, _A1, _A2)>&
1721 function<_Rp(_A0, _A1, _A2)>::operator=(const function& __f)
1723 function(__f).swap(*this);
1727 template<class _Rp, class _A0, class _A1, class _A2>
1728 function<_Rp(_A0, _A1, _A2)>&
1729 function<_Rp(_A0, _A1, _A2)>::operator=(nullptr_t)
1731 if (__f_ == (__base*)&__buf_)
1734 __f_->destroy_deallocate();
1738 template<class _Rp, class _A0, class _A1, class _A2>
1739 template <class _Fp>
1742 !is_integral<_Fp>::value,
1743 function<_Rp(_A0, _A1, _A2)>&
1745 function<_Rp(_A0, _A1, _A2)>::operator=(_Fp __f)
1747 function(_VSTD::move(__f)).swap(*this);
1751 template<class _Rp, class _A0, class _A1, class _A2>
1752 function<_Rp(_A0, _A1, _A2)>::~function()
1754 if (__f_ == (__base*)&__buf_)
1757 __f_->destroy_deallocate();
1760 template<class _Rp, class _A0, class _A1, class _A2>
1762 function<_Rp(_A0, _A1, _A2)>::swap(function& __f)
1764 if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
1766 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
1767 __base* __t = (__base*)&__tempbuf;
1771 __f.__f_->__clone((__base*)&__buf_);
1772 __f.__f_->destroy();
1774 __f_ = (__base*)&__buf_;
1775 __t->__clone((__base*)&__f.__buf_);
1777 __f.__f_ = (__base*)&__f.__buf_;
1779 else if (__f_ == (__base*)&__buf_)
1781 __f_->__clone((__base*)&__f.__buf_);
1784 __f.__f_ = (__base*)&__f.__buf_;
1786 else if (__f.__f_ == (__base*)&__f.__buf_)
1788 __f.__f_->__clone((__base*)&__buf_);
1789 __f.__f_->destroy();
1791 __f_ = (__base*)&__buf_;
1794 _VSTD::swap(__f_, __f.__f_);
1797 template<class _Rp, class _A0, class _A1, class _A2>
1799 function<_Rp(_A0, _A1, _A2)>::operator()(_A0 __a0, _A1 __a1, _A2 __a2) const
1801 #ifndef _LIBCPP_NO_EXCEPTIONS
1803 throw bad_function_call();
1804 #endif // _LIBCPP_NO_EXCEPTIONS
1805 return (*__f_)(__a0, __a1, __a2);
1808 #ifndef _LIBCPP_NO_RTTI
1810 template<class _Rp, class _A0, class _A1, class _A2>
1811 const std::type_info&
1812 function<_Rp(_A0, _A1, _A2)>::target_type() const
1815 return typeid(void);
1816 return __f_->target_type();
1819 template<class _Rp, class _A0, class _A1, class _A2>
1820 template <typename _Tp>
1822 function<_Rp(_A0, _A1, _A2)>::target()
1826 return (_Tp*)__f_->target(typeid(_Tp));
1829 template<class _Rp, class _A0, class _A1, class _A2>
1830 template <typename _Tp>
1832 function<_Rp(_A0, _A1, _A2)>::target() const
1835 return (const _Tp*)0;
1836 return (const _Tp*)__f_->target(typeid(_Tp));
1839 #endif // _LIBCPP_NO_RTTI
1841 template <class _Fp>
1842 inline _LIBCPP_INLINE_VISIBILITY
1844 operator==(const function<_Fp>& __f, nullptr_t) {return !__f;}
1846 template <class _Fp>
1847 inline _LIBCPP_INLINE_VISIBILITY
1849 operator==(nullptr_t, const function<_Fp>& __f) {return !__f;}
1851 template <class _Fp>
1852 inline _LIBCPP_INLINE_VISIBILITY
1854 operator!=(const function<_Fp>& __f, nullptr_t) {return (bool)__f;}
1856 template <class _Fp>
1857 inline _LIBCPP_INLINE_VISIBILITY
1859 operator!=(nullptr_t, const function<_Fp>& __f) {return (bool)__f;}
1861 template <class _Fp>
1862 inline _LIBCPP_INLINE_VISIBILITY
1864 swap(function<_Fp>& __x, function<_Fp>& __y)
1865 {return __x.swap(__y);}
1867 template<class _Tp> struct __is_bind_expression : public false_type {};
1868 template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_bind_expression
1869 : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
1871 template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
1872 template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_placeholder
1873 : public __is_placeholder<typename remove_cv<_Tp>::type> {};
1875 namespace placeholders
1878 template <int _Np> struct __ph {};
1889 extern __ph<10> _10;
1894 struct __is_placeholder<placeholders::__ph<_Np> >
1895 : public integral_constant<int, _Np> {};
1897 template <class _Tp, class _Uj>
1898 inline _LIBCPP_INLINE_VISIBILITY
1900 __mu(reference_wrapper<_Tp> __t, _Uj&)
1905 template <bool _IsBindExpr, class _Ti, class ..._Uj>
1906 struct __mu_return1 {};
1908 template <class _Ti, class ..._Uj>
1909 struct __mu_return1<true, _Ti, _Uj...>
1911 typedef typename result_of<_Ti(_Uj...)>::type type;
1914 template <class _Ti, class ..._Uj, size_t ..._Indx>
1915 inline _LIBCPP_INLINE_VISIBILITY
1916 typename __mu_return1<true, _Ti, _Uj...>::type
1917 __mu_expand(_Ti& __ti, tuple<_Uj...>&& __uj, __tuple_indices<_Indx...>)
1919 __ti(_VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj))...);
1922 template <class _Ti, class ..._Uj>
1923 inline _LIBCPP_INLINE_VISIBILITY
1926 is_bind_expression<_Ti>::value,
1927 typename __mu_return1<is_bind_expression<_Ti>::value, _Ti, _Uj...>::type
1929 __mu(_Ti& __ti, tuple<_Uj...>& __uj)
1931 typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
1932 return __mu_expand(__ti, __uj, __indices());
1935 template <bool IsPh, class _Ti, class _Uj>
1936 struct __mu_return2 {};
1938 template <class _Ti, class _Uj>
1939 struct __mu_return2<true, _Ti, _Uj>
1941 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
1944 template <class _Ti, class _Uj>
1945 inline _LIBCPP_INLINE_VISIBILITY
1948 0 < is_placeholder<_Ti>::value,
1949 typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
1951 __mu(_Ti&, _Uj& __uj)
1953 const size_t _Indx = is_placeholder<_Ti>::value - 1;
1954 // compiler bug workaround
1955 typename tuple_element<_Indx, _Uj>::type __t = _VSTD::get<_Indx>(__uj);
1957 // return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj));
1960 template <class _Ti, class _Uj>
1961 inline _LIBCPP_INLINE_VISIBILITY
1964 !is_bind_expression<_Ti>::value &&
1965 is_placeholder<_Ti>::value == 0 &&
1966 !__is_reference_wrapper<_Ti>::value,
1969 __mu(_Ti& __ti, _Uj& __uj)
1974 template <class _Ti, bool IsBindEx, bool IsPh, class _TupleUj>
1975 struct ____mu_return;
1977 template <class _Ti, class ..._Uj>
1978 struct ____mu_return<_Ti, true, false, tuple<_Uj...> >
1980 typedef typename result_of<_Ti(_Uj...)>::type type;
1983 template <class _Ti, class _TupleUj>
1984 struct ____mu_return<_Ti, false, true, _TupleUj>
1986 typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
1987 _TupleUj>::type&& type;
1990 template <class _Ti, class _TupleUj>
1991 struct ____mu_return<_Ti, false, false, _TupleUj>
1996 template <class _Ti, class _TupleUj>
1998 : public ____mu_return<_Ti,
1999 is_bind_expression<_Ti>::value,
2000 0 < is_placeholder<_Ti>::value,
2005 template <class _Ti, class _TupleUj>
2006 struct __mu_return<reference_wrapper<_Ti>, _TupleUj>
2011 template <class _Fp, class _BoundArgs, class _TupleUj>
2012 struct __bind_return;
2014 template <class _Fp, class ..._BoundArgs, class _TupleUj>
2015 struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
2017 typedef typename __ref_return
2020 typename __mu_return
2028 template <class _Fp, class ..._BoundArgs, class _TupleUj>
2029 struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
2031 typedef typename __ref_return
2034 typename __mu_return
2042 template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
2043 inline _LIBCPP_INLINE_VISIBILITY
2044 typename __bind_return<_Fp, _BoundArgs, _Args>::type
2045 __apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
2048 return __invoke(__f, __mu(_VSTD::get<_Indx>(__bound_args), __args)...);
2051 template<class _Fp, class ..._BoundArgs>
2055 tuple<_BoundArgs...> __bound_args_;
2057 typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
2059 template <class _Gp, class ..._BA>
2060 explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
2061 : __f_(_VSTD::forward<_Gp>(__f)),
2062 __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
2064 template <class ..._Args>
2065 typename __bind_return<_Fp, tuple<_BoundArgs...>, tuple<_Args&&...> >::type
2066 operator()(_Args&& ...__args)
2068 // compiler bug workaround
2069 return __apply_functor(__f_, __bound_args_, __indices(),
2070 tuple<_Args&&...>(__args...));
2073 template <class ..._Args>
2074 typename __bind_return<_Fp, tuple<_BoundArgs...>, tuple<_Args&&...> >::type
2075 operator()(_Args&& ...__args) const
2077 return __apply_functor(__f_, __bound_args_, __indices(),
2078 tuple<_Args&&...>(__args...));
2082 template<class _Fp, class ..._BoundArgs>
2083 struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
2085 template<class _Rp, class _Fp, class ..._BoundArgs>
2087 : public __bind<_Fp, _BoundArgs...>
2089 typedef __bind<_Fp, _BoundArgs...> base;
2091 typedef _Rp result_type;
2093 template <class _Gp, class ..._BA>
2094 explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
2095 : base(_VSTD::forward<_Gp>(__f),
2096 _VSTD::forward<_BA>(__bound_args)...) {}
2098 template <class ..._Args>
2100 operator()(_Args&& ...__args)
2102 return base::operator()(_VSTD::forward<_Args>(__args)...);
2105 template <class ..._Args>
2107 operator()(_Args&& ...__args) const
2109 return base::operator()(_VSTD::forward<_Args>(__args)...);
2113 template<class _Rp, class _Fp, class ..._BoundArgs>
2114 struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
2116 template<class _Fp, class ..._BoundArgs>
2117 inline _LIBCPP_INLINE_VISIBILITY
2118 __bind<typename decay<_Fp>::type, typename decay<_BoundArgs>::type...>
2119 bind(_Fp&& __f, _BoundArgs&&... __bound_args)
2121 typedef __bind<typename decay<_Fp>::type, typename decay<_BoundArgs>::type...> type;
2122 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
2125 template<class _Rp, class _Fp, class ..._BoundArgs>
2126 inline _LIBCPP_INLINE_VISIBILITY
2127 __bind_r<_Rp, typename decay<_Fp>::type, typename decay<_BoundArgs>::type...>
2128 bind(_Fp&& __f, _BoundArgs&&... __bound_args)
2130 typedef __bind_r<_Rp, typename decay<_Fp>::type, typename decay<_BoundArgs>::type...> type;
2131 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
2135 #endif // _LIBCPP_FUNCTIONAL_03