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)
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)
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)
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::*)()>
106 mem_fn(_Rp (_Tp::* __pm)() const)
108 return __mem_fn<_Rp (_Tp::*)()>(__pm);
111 template<class _Rp, class _Tp, class _A0>
112 inline _LIBCPP_INLINE_VISIBILITY
113 __mem_fn<_Rp (_Tp::*)(_A0)>
114 mem_fn(_Rp (_Tp::* __pm)(_A0) const)
116 return __mem_fn<_Rp (_Tp::*)(_A0)>(__pm);
119 template<class _Rp, class _Tp, class _A0, class _A1>
120 inline _LIBCPP_INLINE_VISIBILITY
121 __mem_fn<_Rp (_Tp::*)(_A0, _A1)>
122 mem_fn(_Rp (_Tp::* __pm)(_A0, _A1) const)
124 return __mem_fn<_Rp (_Tp::*)(_A0, _A1)>(__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)>
130 mem_fn(_Rp (_Tp::* __pm)(_A0, _A1, _A2) const)
132 return __mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2)>(__pm);
135 template<class _Rp, class _Tp>
136 inline _LIBCPP_INLINE_VISIBILITY
137 __mem_fn<_Rp (_Tp::*)()>
138 mem_fn(_Rp (_Tp::* __pm)() volatile)
140 return __mem_fn<_Rp (_Tp::*)()>(__pm);
143 template<class _Rp, class _Tp, class _A0>
144 inline _LIBCPP_INLINE_VISIBILITY
145 __mem_fn<_Rp (_Tp::*)(_A0)>
146 mem_fn(_Rp (_Tp::* __pm)(_A0) volatile)
148 return __mem_fn<_Rp (_Tp::*)(_A0)>(__pm);
151 template<class _Rp, class _Tp, class _A0, class _A1>
152 inline _LIBCPP_INLINE_VISIBILITY
153 __mem_fn<_Rp (_Tp::*)(_A0, _A1)>
154 mem_fn(_Rp (_Tp::* __pm)(_A0, _A1) volatile)
156 return __mem_fn<_Rp (_Tp::*)(_A0, _A1)>(__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)>
162 mem_fn(_Rp (_Tp::* __pm)(_A0, _A1, _A2) volatile)
164 return __mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2)>(__pm);
167 template<class _Rp, class _Tp>
168 inline _LIBCPP_INLINE_VISIBILITY
169 __mem_fn<_Rp (_Tp::*)()>
170 mem_fn(_Rp (_Tp::* __pm)() const volatile)
172 return __mem_fn<_Rp (_Tp::*)()>(__pm);
175 template<class _Rp, class _Tp, class _A0>
176 inline _LIBCPP_INLINE_VISIBILITY
177 __mem_fn<_Rp (_Tp::*)(_A0)>
178 mem_fn(_Rp (_Tp::* __pm)(_A0) const volatile)
180 return __mem_fn<_Rp (_Tp::*)(_A0)>(__pm);
183 template<class _Rp, class _Tp, class _A0, class _A1>
184 inline _LIBCPP_INLINE_VISIBILITY
185 __mem_fn<_Rp (_Tp::*)(_A0, _A1)>
186 mem_fn(_Rp (_Tp::* __pm)(_A0, _A1) const volatile)
188 return __mem_fn<_Rp (_Tp::*)(_A0, _A1)>(__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)>
194 mem_fn(_Rp (_Tp::* __pm)(_A0, _A1, _A2) const volatile)
196 return __mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2)>(__pm);
201 class _LIBCPP_EXCEPTION_ABI bad_function_call
206 template<class _Fp> class _LIBCPP_TYPE_VIS 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 function<_Rp()>
649 typedef __function::__base<_Rp()> __base;
650 aligned_storage<3*sizeof(void*)>::type __buf_;
654 static bool __not_null(const _Fp&) {return true;}
656 static bool __not_null(const function<_Rp()>& __p) {return __p;}
658 typedef _Rp result_type;
660 // 20.7.16.2.1, construct/copy/destroy:
661 _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {}
662 _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {}
663 function(const function&);
666 typename enable_if<!is_integral<_Fp>::value>::type* = 0);
668 template<class _Alloc>
669 _LIBCPP_INLINE_VISIBILITY
670 function(allocator_arg_t, const _Alloc&) : __f_(0) {}
671 template<class _Alloc>
672 _LIBCPP_INLINE_VISIBILITY
673 function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {}
674 template<class _Alloc>
675 function(allocator_arg_t, const _Alloc&, const function&);
676 template<class _Fp, class _Alloc>
677 function(allocator_arg_t, const _Alloc& __a, _Fp __f,
678 typename enable_if<!is_integral<_Fp>::value>::type* = 0);
680 function& operator=(const function&);
681 function& operator=(nullptr_t);
685 !is_integral<_Fp>::value,
692 // 20.7.16.2.2, function modifiers:
693 void swap(function&);
694 template<class _Fp, class _Alloc>
695 _LIBCPP_INLINE_VISIBILITY
696 void assign(_Fp __f, const _Alloc& __a)
697 {function(allocator_arg, __a, __f).swap(*this);}
699 // 20.7.16.2.3, function capacity:
700 _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;}
703 // deleted overloads close possible hole in the type system
705 bool operator==(const function<_R2()>&) const;// = delete;
707 bool operator!=(const function<_R2()>&) const;// = delete;
709 // 20.7.16.2.4, function invocation:
710 _Rp operator()() const;
712 #ifndef _LIBCPP_NO_RTTI
713 // 20.7.16.2.5, function target access:
714 const std::type_info& target_type() const;
715 template <typename _Tp> _Tp* target();
716 template <typename _Tp> const _Tp* target() const;
717 #endif // _LIBCPP_NO_RTTI
721 function<_Rp()>::function(const function& __f)
725 else if (__f.__f_ == (const __base*)&__f.__buf_)
727 __f_ = (__base*)&__buf_;
728 __f.__f_->__clone(__f_);
731 __f_ = __f.__f_->__clone();
735 template<class _Alloc>
736 function<_Rp()>::function(allocator_arg_t, const _Alloc&, const function& __f)
740 else if (__f.__f_ == (const __base*)&__f.__buf_)
742 __f_ = (__base*)&__buf_;
743 __f.__f_->__clone(__f_);
746 __f_ = __f.__f_->__clone();
751 function<_Rp()>::function(_Fp __f,
752 typename enable_if<!is_integral<_Fp>::value>::type*)
757 typedef __function::__func<_Fp, allocator<_Fp>, _Rp()> _FF;
758 if (sizeof(_FF) <= sizeof(__buf_))
760 __f_ = (__base*)&__buf_;
761 ::new (__f_) _FF(__f);
765 typedef allocator<_FF> _Ap;
767 typedef __allocator_destructor<_Ap> _Dp;
768 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
769 ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a));
770 __f_ = __hold.release();
776 template <class _Fp, class _Alloc>
777 function<_Rp()>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
778 typename enable_if<!is_integral<_Fp>::value>::type*)
781 typedef allocator_traits<_Alloc> __alloc_traits;
784 typedef __function::__func<_Fp, _Alloc, _Rp()> _FF;
785 if (sizeof(_FF) <= sizeof(__buf_))
787 __f_ = (__base*)&__buf_;
788 ::new (__f_) _FF(__f);
792 typedef typename __alloc_traits::template
793 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
796 rebind_alloc<_FF>::other
800 typedef __allocator_destructor<_Ap> _Dp;
801 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
802 ::new (__hold.get()) _FF(__f, _Alloc(__a));
803 __f_ = __hold.release();
810 function<_Rp()>::operator=(const function& __f)
812 function(__f).swap(*this);
818 function<_Rp()>::operator=(nullptr_t)
820 if (__f_ == (__base*)&__buf_)
823 __f_->destroy_deallocate();
831 !is_integral<_Fp>::value,
834 function<_Rp()>::operator=(_Fp __f)
836 function(_VSTD::move(__f)).swap(*this);
841 function<_Rp()>::~function()
843 if (__f_ == (__base*)&__buf_)
846 __f_->destroy_deallocate();
851 function<_Rp()>::swap(function& __f)
853 if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
855 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
856 __base* __t = (__base*)&__tempbuf;
860 __f.__f_->__clone((__base*)&__buf_);
863 __f_ = (__base*)&__buf_;
864 __t->__clone((__base*)&__f.__buf_);
866 __f.__f_ = (__base*)&__f.__buf_;
868 else if (__f_ == (__base*)&__buf_)
870 __f_->__clone((__base*)&__f.__buf_);
873 __f.__f_ = (__base*)&__f.__buf_;
875 else if (__f.__f_ == (__base*)&__f.__buf_)
877 __f.__f_->__clone((__base*)&__buf_);
880 __f_ = (__base*)&__buf_;
883 _VSTD::swap(__f_, __f.__f_);
888 function<_Rp()>::operator()() const
890 #ifndef _LIBCPP_NO_EXCEPTIONS
892 throw bad_function_call();
893 #endif // _LIBCPP_NO_EXCEPTIONS
897 #ifndef _LIBCPP_NO_RTTI
900 const std::type_info&
901 function<_Rp()>::target_type() const
905 return __f_->target_type();
909 template <typename _Tp>
911 function<_Rp()>::target()
915 return (_Tp*)__f_->target(typeid(_Tp));
919 template <typename _Tp>
921 function<_Rp()>::target() const
924 return (const _Tp*)0;
925 return (const _Tp*)__f_->target(typeid(_Tp));
928 #endif // _LIBCPP_NO_RTTI
930 template<class _Rp, class _A0>
931 class _LIBCPP_TYPE_VIS function<_Rp(_A0)>
932 : public unary_function<_A0, _Rp>
934 typedef __function::__base<_Rp(_A0)> __base;
935 aligned_storage<3*sizeof(void*)>::type __buf_;
939 _LIBCPP_INLINE_VISIBILITY
940 static bool __not_null(const _Fp&) {return true;}
941 template <class _R2, class _B0>
942 _LIBCPP_INLINE_VISIBILITY
943 static bool __not_null(_R2 (*__p)(_B0)) {return __p;}
944 template <class _R2, class _Cp>
945 _LIBCPP_INLINE_VISIBILITY
946 static bool __not_null(_R2 (_Cp::*__p)()) {return __p;}
947 template <class _R2, class _Cp>
948 _LIBCPP_INLINE_VISIBILITY
949 static bool __not_null(_R2 (_Cp::*__p)() const) {return __p;}
950 template <class _R2, class _Cp>
951 _LIBCPP_INLINE_VISIBILITY
952 static bool __not_null(_R2 (_Cp::*__p)() volatile) {return __p;}
953 template <class _R2, class _Cp>
954 _LIBCPP_INLINE_VISIBILITY
955 static bool __not_null(_R2 (_Cp::*__p)() const volatile) {return __p;}
956 template <class _R2, class _B0>
957 _LIBCPP_INLINE_VISIBILITY
958 static bool __not_null(const function<_Rp(_B0)>& __p) {return __p;}
960 typedef _Rp result_type;
962 // 20.7.16.2.1, construct/copy/destroy:
963 _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {}
964 _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {}
965 function(const function&);
968 typename enable_if<!is_integral<_Fp>::value>::type* = 0);
970 template<class _Alloc>
971 _LIBCPP_INLINE_VISIBILITY
972 function(allocator_arg_t, const _Alloc&) : __f_(0) {}
973 template<class _Alloc>
974 _LIBCPP_INLINE_VISIBILITY
975 function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {}
976 template<class _Alloc>
977 function(allocator_arg_t, const _Alloc&, const function&);
978 template<class _Fp, class _Alloc>
979 function(allocator_arg_t, const _Alloc& __a, _Fp __f,
980 typename enable_if<!is_integral<_Fp>::value>::type* = 0);
982 function& operator=(const function&);
983 function& operator=(nullptr_t);
987 !is_integral<_Fp>::value,
994 // 20.7.16.2.2, function modifiers:
995 void swap(function&);
996 template<class _Fp, class _Alloc>
997 _LIBCPP_INLINE_VISIBILITY
998 void assign(_Fp __f, const _Alloc& __a)
999 {function(allocator_arg, __a, __f).swap(*this);}
1001 // 20.7.16.2.3, function capacity:
1002 _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;}
1005 // deleted overloads close possible hole in the type system
1006 template<class _R2, class _B0>
1007 bool operator==(const function<_R2(_B0)>&) const;// = delete;
1008 template<class _R2, class _B0>
1009 bool operator!=(const function<_R2(_B0)>&) const;// = delete;
1011 // 20.7.16.2.4, function invocation:
1012 _Rp operator()(_A0) const;
1014 #ifndef _LIBCPP_NO_RTTI
1015 // 20.7.16.2.5, function target access:
1016 const std::type_info& target_type() const;
1017 template <typename _Tp> _Tp* target();
1018 template <typename _Tp> const _Tp* target() const;
1019 #endif // _LIBCPP_NO_RTTI
1022 template<class _Rp, class _A0>
1023 function<_Rp(_A0)>::function(const function& __f)
1027 else if (__f.__f_ == (const __base*)&__f.__buf_)
1029 __f_ = (__base*)&__buf_;
1030 __f.__f_->__clone(__f_);
1033 __f_ = __f.__f_->__clone();
1036 template<class _Rp, class _A0>
1037 template<class _Alloc>
1038 function<_Rp(_A0)>::function(allocator_arg_t, const _Alloc&, const function& __f)
1042 else if (__f.__f_ == (const __base*)&__f.__buf_)
1044 __f_ = (__base*)&__buf_;
1045 __f.__f_->__clone(__f_);
1048 __f_ = __f.__f_->__clone();
1051 template<class _Rp, class _A0>
1052 template <class _Fp>
1053 function<_Rp(_A0)>::function(_Fp __f,
1054 typename enable_if<!is_integral<_Fp>::value>::type*)
1057 if (__not_null(__f))
1059 typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0)> _FF;
1060 if (sizeof(_FF) <= sizeof(__buf_))
1062 __f_ = (__base*)&__buf_;
1063 ::new (__f_) _FF(__f);
1067 typedef allocator<_FF> _Ap;
1069 typedef __allocator_destructor<_Ap> _Dp;
1070 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1071 ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a));
1072 __f_ = __hold.release();
1077 template<class _Rp, class _A0>
1078 template <class _Fp, class _Alloc>
1079 function<_Rp(_A0)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
1080 typename enable_if<!is_integral<_Fp>::value>::type*)
1083 typedef allocator_traits<_Alloc> __alloc_traits;
1084 if (__not_null(__f))
1086 typedef __function::__func<_Fp, _Alloc, _Rp(_A0)> _FF;
1087 if (sizeof(_FF) <= sizeof(__buf_))
1089 __f_ = (__base*)&__buf_;
1090 ::new (__f_) _FF(__f);
1094 typedef typename __alloc_traits::template
1095 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1098 rebind_alloc<_FF>::other
1102 typedef __allocator_destructor<_Ap> _Dp;
1103 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1104 ::new (__hold.get()) _FF(__f, _Alloc(__a));
1105 __f_ = __hold.release();
1110 template<class _Rp, class _A0>
1112 function<_Rp(_A0)>::operator=(const function& __f)
1114 function(__f).swap(*this);
1118 template<class _Rp, class _A0>
1120 function<_Rp(_A0)>::operator=(nullptr_t)
1122 if (__f_ == (__base*)&__buf_)
1125 __f_->destroy_deallocate();
1129 template<class _Rp, class _A0>
1130 template <class _Fp>
1133 !is_integral<_Fp>::value,
1136 function<_Rp(_A0)>::operator=(_Fp __f)
1138 function(_VSTD::move(__f)).swap(*this);
1142 template<class _Rp, class _A0>
1143 function<_Rp(_A0)>::~function()
1145 if (__f_ == (__base*)&__buf_)
1148 __f_->destroy_deallocate();
1151 template<class _Rp, class _A0>
1153 function<_Rp(_A0)>::swap(function& __f)
1155 if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
1157 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
1158 __base* __t = (__base*)&__tempbuf;
1162 __f.__f_->__clone((__base*)&__buf_);
1163 __f.__f_->destroy();
1165 __f_ = (__base*)&__buf_;
1166 __t->__clone((__base*)&__f.__buf_);
1168 __f.__f_ = (__base*)&__f.__buf_;
1170 else if (__f_ == (__base*)&__buf_)
1172 __f_->__clone((__base*)&__f.__buf_);
1175 __f.__f_ = (__base*)&__f.__buf_;
1177 else if (__f.__f_ == (__base*)&__f.__buf_)
1179 __f.__f_->__clone((__base*)&__buf_);
1180 __f.__f_->destroy();
1182 __f_ = (__base*)&__buf_;
1185 _VSTD::swap(__f_, __f.__f_);
1188 template<class _Rp, class _A0>
1190 function<_Rp(_A0)>::operator()(_A0 __a0) const
1192 #ifndef _LIBCPP_NO_EXCEPTIONS
1194 throw bad_function_call();
1195 #endif // _LIBCPP_NO_EXCEPTIONS
1196 return (*__f_)(__a0);
1199 #ifndef _LIBCPP_NO_RTTI
1201 template<class _Rp, class _A0>
1202 const std::type_info&
1203 function<_Rp(_A0)>::target_type() const
1206 return typeid(void);
1207 return __f_->target_type();
1210 template<class _Rp, class _A0>
1211 template <typename _Tp>
1213 function<_Rp(_A0)>::target()
1217 return (_Tp*)__f_->target(typeid(_Tp));
1220 template<class _Rp, class _A0>
1221 template <typename _Tp>
1223 function<_Rp(_A0)>::target() const
1226 return (const _Tp*)0;
1227 return (const _Tp*)__f_->target(typeid(_Tp));
1230 #endif // _LIBCPP_NO_RTTI
1232 template<class _Rp, class _A0, class _A1>
1233 class _LIBCPP_TYPE_VIS function<_Rp(_A0, _A1)>
1234 : public binary_function<_A0, _A1, _Rp>
1236 typedef __function::__base<_Rp(_A0, _A1)> __base;
1237 aligned_storage<3*sizeof(void*)>::type __buf_;
1240 template <class _Fp>
1241 _LIBCPP_INLINE_VISIBILITY
1242 static bool __not_null(const _Fp&) {return true;}
1243 template <class _R2, class _B0, class _B1>
1244 _LIBCPP_INLINE_VISIBILITY
1245 static bool __not_null(_R2 (*__p)(_B0, _B1)) {return __p;}
1246 template <class _R2, class _Cp, class _B1>
1247 _LIBCPP_INLINE_VISIBILITY
1248 static bool __not_null(_R2 (_Cp::*__p)(_B1)) {return __p;}
1249 template <class _R2, class _Cp, class _B1>
1250 _LIBCPP_INLINE_VISIBILITY
1251 static bool __not_null(_R2 (_Cp::*__p)(_B1) const) {return __p;}
1252 template <class _R2, class _Cp, class _B1>
1253 _LIBCPP_INLINE_VISIBILITY
1254 static bool __not_null(_R2 (_Cp::*__p)(_B1) volatile) {return __p;}
1255 template <class _R2, class _Cp, class _B1>
1256 _LIBCPP_INLINE_VISIBILITY
1257 static bool __not_null(_R2 (_Cp::*__p)(_B1) const volatile) {return __p;}
1258 template <class _R2, class _B0, class _B1>
1259 _LIBCPP_INLINE_VISIBILITY
1260 static bool __not_null(const function<_Rp(_B0, _B1)>& __p) {return __p;}
1262 typedef _Rp result_type;
1264 // 20.7.16.2.1, construct/copy/destroy:
1265 _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {}
1266 _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {}
1267 function(const function&);
1270 typename enable_if<!is_integral<_Fp>::value>::type* = 0);
1272 template<class _Alloc>
1273 _LIBCPP_INLINE_VISIBILITY
1274 function(allocator_arg_t, const _Alloc&) : __f_(0) {}
1275 template<class _Alloc>
1276 _LIBCPP_INLINE_VISIBILITY
1277 function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {}
1278 template<class _Alloc>
1279 function(allocator_arg_t, const _Alloc&, const function&);
1280 template<class _Fp, class _Alloc>
1281 function(allocator_arg_t, const _Alloc& __a, _Fp __f,
1282 typename enable_if<!is_integral<_Fp>::value>::type* = 0);
1284 function& operator=(const function&);
1285 function& operator=(nullptr_t);
1289 !is_integral<_Fp>::value,
1296 // 20.7.16.2.2, function modifiers:
1297 void swap(function&);
1298 template<class _Fp, class _Alloc>
1299 _LIBCPP_INLINE_VISIBILITY
1300 void assign(_Fp __f, const _Alloc& __a)
1301 {function(allocator_arg, __a, __f).swap(*this);}
1303 // 20.7.16.2.3, function capacity:
1304 operator bool() const {return __f_;}
1307 // deleted overloads close possible hole in the type system
1308 template<class _R2, class _B0, class _B1>
1309 bool operator==(const function<_R2(_B0, _B1)>&) const;// = delete;
1310 template<class _R2, class _B0, class _B1>
1311 bool operator!=(const function<_R2(_B0, _B1)>&) const;// = delete;
1313 // 20.7.16.2.4, function invocation:
1314 _Rp operator()(_A0, _A1) const;
1316 #ifndef _LIBCPP_NO_RTTI
1317 // 20.7.16.2.5, function target access:
1318 const std::type_info& target_type() const;
1319 template <typename _Tp> _Tp* target();
1320 template <typename _Tp> const _Tp* target() const;
1321 #endif // _LIBCPP_NO_RTTI
1324 template<class _Rp, class _A0, class _A1>
1325 function<_Rp(_A0, _A1)>::function(const function& __f)
1329 else if (__f.__f_ == (const __base*)&__f.__buf_)
1331 __f_ = (__base*)&__buf_;
1332 __f.__f_->__clone(__f_);
1335 __f_ = __f.__f_->__clone();
1338 template<class _Rp, class _A0, class _A1>
1339 template<class _Alloc>
1340 function<_Rp(_A0, _A1)>::function(allocator_arg_t, const _Alloc&, const function& __f)
1344 else if (__f.__f_ == (const __base*)&__f.__buf_)
1346 __f_ = (__base*)&__buf_;
1347 __f.__f_->__clone(__f_);
1350 __f_ = __f.__f_->__clone();
1353 template<class _Rp, class _A0, class _A1>
1354 template <class _Fp>
1355 function<_Rp(_A0, _A1)>::function(_Fp __f,
1356 typename enable_if<!is_integral<_Fp>::value>::type*)
1359 if (__not_null(__f))
1361 typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0, _A1)> _FF;
1362 if (sizeof(_FF) <= sizeof(__buf_))
1364 __f_ = (__base*)&__buf_;
1365 ::new (__f_) _FF(__f);
1369 typedef allocator<_FF> _Ap;
1371 typedef __allocator_destructor<_Ap> _Dp;
1372 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1373 ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a));
1374 __f_ = __hold.release();
1379 template<class _Rp, class _A0, class _A1>
1380 template <class _Fp, class _Alloc>
1381 function<_Rp(_A0, _A1)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
1382 typename enable_if<!is_integral<_Fp>::value>::type*)
1385 typedef allocator_traits<_Alloc> __alloc_traits;
1386 if (__not_null(__f))
1388 typedef __function::__func<_Fp, _Alloc, _Rp(_A0, _A1)> _FF;
1389 if (sizeof(_FF) <= sizeof(__buf_))
1391 __f_ = (__base*)&__buf_;
1392 ::new (__f_) _FF(__f);
1396 typedef typename __alloc_traits::template
1397 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1400 rebind_alloc<_FF>::other
1404 typedef __allocator_destructor<_Ap> _Dp;
1405 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1406 ::new (__hold.get()) _FF(__f, _Alloc(__a));
1407 __f_ = __hold.release();
1412 template<class _Rp, class _A0, class _A1>
1413 function<_Rp(_A0, _A1)>&
1414 function<_Rp(_A0, _A1)>::operator=(const function& __f)
1416 function(__f).swap(*this);
1420 template<class _Rp, class _A0, class _A1>
1421 function<_Rp(_A0, _A1)>&
1422 function<_Rp(_A0, _A1)>::operator=(nullptr_t)
1424 if (__f_ == (__base*)&__buf_)
1427 __f_->destroy_deallocate();
1431 template<class _Rp, class _A0, class _A1>
1432 template <class _Fp>
1435 !is_integral<_Fp>::value,
1436 function<_Rp(_A0, _A1)>&
1438 function<_Rp(_A0, _A1)>::operator=(_Fp __f)
1440 function(_VSTD::move(__f)).swap(*this);
1444 template<class _Rp, class _A0, class _A1>
1445 function<_Rp(_A0, _A1)>::~function()
1447 if (__f_ == (__base*)&__buf_)
1450 __f_->destroy_deallocate();
1453 template<class _Rp, class _A0, class _A1>
1455 function<_Rp(_A0, _A1)>::swap(function& __f)
1457 if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
1459 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
1460 __base* __t = (__base*)&__tempbuf;
1464 __f.__f_->__clone((__base*)&__buf_);
1465 __f.__f_->destroy();
1467 __f_ = (__base*)&__buf_;
1468 __t->__clone((__base*)&__f.__buf_);
1470 __f.__f_ = (__base*)&__f.__buf_;
1472 else if (__f_ == (__base*)&__buf_)
1474 __f_->__clone((__base*)&__f.__buf_);
1477 __f.__f_ = (__base*)&__f.__buf_;
1479 else if (__f.__f_ == (__base*)&__f.__buf_)
1481 __f.__f_->__clone((__base*)&__buf_);
1482 __f.__f_->destroy();
1484 __f_ = (__base*)&__buf_;
1487 _VSTD::swap(__f_, __f.__f_);
1490 template<class _Rp, class _A0, class _A1>
1492 function<_Rp(_A0, _A1)>::operator()(_A0 __a0, _A1 __a1) const
1494 #ifndef _LIBCPP_NO_EXCEPTIONS
1496 throw bad_function_call();
1497 #endif // _LIBCPP_NO_EXCEPTIONS
1498 return (*__f_)(__a0, __a1);
1501 #ifndef _LIBCPP_NO_RTTI
1503 template<class _Rp, class _A0, class _A1>
1504 const std::type_info&
1505 function<_Rp(_A0, _A1)>::target_type() const
1508 return typeid(void);
1509 return __f_->target_type();
1512 template<class _Rp, class _A0, class _A1>
1513 template <typename _Tp>
1515 function<_Rp(_A0, _A1)>::target()
1519 return (_Tp*)__f_->target(typeid(_Tp));
1522 template<class _Rp, class _A0, class _A1>
1523 template <typename _Tp>
1525 function<_Rp(_A0, _A1)>::target() const
1528 return (const _Tp*)0;
1529 return (const _Tp*)__f_->target(typeid(_Tp));
1532 #endif // _LIBCPP_NO_RTTI
1534 template<class _Rp, class _A0, class _A1, class _A2>
1535 class _LIBCPP_TYPE_VIS function<_Rp(_A0, _A1, _A2)>
1537 typedef __function::__base<_Rp(_A0, _A1, _A2)> __base;
1538 aligned_storage<3*sizeof(void*)>::type __buf_;
1541 template <class _Fp>
1542 _LIBCPP_INLINE_VISIBILITY
1543 static bool __not_null(const _Fp&) {return true;}
1544 template <class _R2, class _B0, class _B1, class _B2>
1545 _LIBCPP_INLINE_VISIBILITY
1546 static bool __not_null(_R2 (*__p)(_B0, _B1, _B2)) {return __p;}
1547 template <class _R2, class _Cp, class _B1, class _B2>
1548 _LIBCPP_INLINE_VISIBILITY
1549 static bool __not_null(_R2 (_Cp::*__p)(_B1, _B2)) {return __p;}
1550 template <class _R2, class _Cp, class _B1, class _B2>
1551 _LIBCPP_INLINE_VISIBILITY
1552 static bool __not_null(_R2 (_Cp::*__p)(_B1, _B2) const) {return __p;}
1553 template <class _R2, class _Cp, class _B1, class _B2>
1554 _LIBCPP_INLINE_VISIBILITY
1555 static bool __not_null(_R2 (_Cp::*__p)(_B1, _B2) volatile) {return __p;}
1556 template <class _R2, class _Cp, class _B1, class _B2>
1557 _LIBCPP_INLINE_VISIBILITY
1558 static bool __not_null(_R2 (_Cp::*__p)(_B1, _B2) const volatile) {return __p;}
1559 template <class _R2, class _B0, class _B1, class _B2>
1560 _LIBCPP_INLINE_VISIBILITY
1561 static bool __not_null(const function<_Rp(_B0, _B1, _B2)>& __p) {return __p;}
1563 typedef _Rp result_type;
1565 // 20.7.16.2.1, construct/copy/destroy:
1566 _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {}
1567 _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {}
1568 function(const function&);
1571 typename enable_if<!is_integral<_Fp>::value>::type* = 0);
1573 template<class _Alloc>
1574 _LIBCPP_INLINE_VISIBILITY
1575 function(allocator_arg_t, const _Alloc&) : __f_(0) {}
1576 template<class _Alloc>
1577 _LIBCPP_INLINE_VISIBILITY
1578 function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {}
1579 template<class _Alloc>
1580 function(allocator_arg_t, const _Alloc&, const function&);
1581 template<class _Fp, class _Alloc>
1582 function(allocator_arg_t, const _Alloc& __a, _Fp __f,
1583 typename enable_if<!is_integral<_Fp>::value>::type* = 0);
1585 function& operator=(const function&);
1586 function& operator=(nullptr_t);
1590 !is_integral<_Fp>::value,
1597 // 20.7.16.2.2, function modifiers:
1598 void swap(function&);
1599 template<class _Fp, class _Alloc>
1600 _LIBCPP_INLINE_VISIBILITY
1601 void assign(_Fp __f, const _Alloc& __a)
1602 {function(allocator_arg, __a, __f).swap(*this);}
1604 // 20.7.16.2.3, function capacity:
1605 _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;}
1608 // deleted overloads close possible hole in the type system
1609 template<class _R2, class _B0, class _B1, class _B2>
1610 bool operator==(const function<_R2(_B0, _B1, _B2)>&) const;// = delete;
1611 template<class _R2, class _B0, class _B1, class _B2>
1612 bool operator!=(const function<_R2(_B0, _B1, _B2)>&) const;// = delete;
1614 // 20.7.16.2.4, function invocation:
1615 _Rp operator()(_A0, _A1, _A2) const;
1617 #ifndef _LIBCPP_NO_RTTI
1618 // 20.7.16.2.5, function target access:
1619 const std::type_info& target_type() const;
1620 template <typename _Tp> _Tp* target();
1621 template <typename _Tp> const _Tp* target() const;
1622 #endif // _LIBCPP_NO_RTTI
1625 template<class _Rp, class _A0, class _A1, class _A2>
1626 function<_Rp(_A0, _A1, _A2)>::function(const function& __f)
1630 else if (__f.__f_ == (const __base*)&__f.__buf_)
1632 __f_ = (__base*)&__buf_;
1633 __f.__f_->__clone(__f_);
1636 __f_ = __f.__f_->__clone();
1639 template<class _Rp, class _A0, class _A1, class _A2>
1640 template<class _Alloc>
1641 function<_Rp(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc&,
1642 const function& __f)
1646 else if (__f.__f_ == (const __base*)&__f.__buf_)
1648 __f_ = (__base*)&__buf_;
1649 __f.__f_->__clone(__f_);
1652 __f_ = __f.__f_->__clone();
1655 template<class _Rp, class _A0, class _A1, class _A2>
1656 template <class _Fp>
1657 function<_Rp(_A0, _A1, _A2)>::function(_Fp __f,
1658 typename enable_if<!is_integral<_Fp>::value>::type*)
1661 if (__not_null(__f))
1663 typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0, _A1, _A2)> _FF;
1664 if (sizeof(_FF) <= sizeof(__buf_))
1666 __f_ = (__base*)&__buf_;
1667 ::new (__f_) _FF(__f);
1671 typedef allocator<_FF> _Ap;
1673 typedef __allocator_destructor<_Ap> _Dp;
1674 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1675 ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a));
1676 __f_ = __hold.release();
1681 template<class _Rp, class _A0, class _A1, class _A2>
1682 template <class _Fp, class _Alloc>
1683 function<_Rp(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
1684 typename enable_if<!is_integral<_Fp>::value>::type*)
1687 typedef allocator_traits<_Alloc> __alloc_traits;
1688 if (__not_null(__f))
1690 typedef __function::__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)> _FF;
1691 if (sizeof(_FF) <= sizeof(__buf_))
1693 __f_ = (__base*)&__buf_;
1694 ::new (__f_) _FF(__f);
1698 typedef typename __alloc_traits::template
1699 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1702 rebind_alloc<_FF>::other
1706 typedef __allocator_destructor<_Ap> _Dp;
1707 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1708 ::new (__hold.get()) _FF(__f, _Alloc(__a));
1709 __f_ = __hold.release();
1714 template<class _Rp, class _A0, class _A1, class _A2>
1715 function<_Rp(_A0, _A1, _A2)>&
1716 function<_Rp(_A0, _A1, _A2)>::operator=(const function& __f)
1718 function(__f).swap(*this);
1722 template<class _Rp, class _A0, class _A1, class _A2>
1723 function<_Rp(_A0, _A1, _A2)>&
1724 function<_Rp(_A0, _A1, _A2)>::operator=(nullptr_t)
1726 if (__f_ == (__base*)&__buf_)
1729 __f_->destroy_deallocate();
1733 template<class _Rp, class _A0, class _A1, class _A2>
1734 template <class _Fp>
1737 !is_integral<_Fp>::value,
1738 function<_Rp(_A0, _A1, _A2)>&
1740 function<_Rp(_A0, _A1, _A2)>::operator=(_Fp __f)
1742 function(_VSTD::move(__f)).swap(*this);
1746 template<class _Rp, class _A0, class _A1, class _A2>
1747 function<_Rp(_A0, _A1, _A2)>::~function()
1749 if (__f_ == (__base*)&__buf_)
1752 __f_->destroy_deallocate();
1755 template<class _Rp, class _A0, class _A1, class _A2>
1757 function<_Rp(_A0, _A1, _A2)>::swap(function& __f)
1759 if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
1761 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
1762 __base* __t = (__base*)&__tempbuf;
1766 __f.__f_->__clone((__base*)&__buf_);
1767 __f.__f_->destroy();
1769 __f_ = (__base*)&__buf_;
1770 __t->__clone((__base*)&__f.__buf_);
1772 __f.__f_ = (__base*)&__f.__buf_;
1774 else if (__f_ == (__base*)&__buf_)
1776 __f_->__clone((__base*)&__f.__buf_);
1779 __f.__f_ = (__base*)&__f.__buf_;
1781 else if (__f.__f_ == (__base*)&__f.__buf_)
1783 __f.__f_->__clone((__base*)&__buf_);
1784 __f.__f_->destroy();
1786 __f_ = (__base*)&__buf_;
1789 _VSTD::swap(__f_, __f.__f_);
1792 template<class _Rp, class _A0, class _A1, class _A2>
1794 function<_Rp(_A0, _A1, _A2)>::operator()(_A0 __a0, _A1 __a1, _A2 __a2) const
1796 #ifndef _LIBCPP_NO_EXCEPTIONS
1798 throw bad_function_call();
1799 #endif // _LIBCPP_NO_EXCEPTIONS
1800 return (*__f_)(__a0, __a1, __a2);
1803 #ifndef _LIBCPP_NO_RTTI
1805 template<class _Rp, class _A0, class _A1, class _A2>
1806 const std::type_info&
1807 function<_Rp(_A0, _A1, _A2)>::target_type() const
1810 return typeid(void);
1811 return __f_->target_type();
1814 template<class _Rp, class _A0, class _A1, class _A2>
1815 template <typename _Tp>
1817 function<_Rp(_A0, _A1, _A2)>::target()
1821 return (_Tp*)__f_->target(typeid(_Tp));
1824 template<class _Rp, class _A0, class _A1, class _A2>
1825 template <typename _Tp>
1827 function<_Rp(_A0, _A1, _A2)>::target() const
1830 return (const _Tp*)0;
1831 return (const _Tp*)__f_->target(typeid(_Tp));
1834 #endif // _LIBCPP_NO_RTTI
1836 template <class _Fp>
1837 inline _LIBCPP_INLINE_VISIBILITY
1839 operator==(const function<_Fp>& __f, nullptr_t) {return !__f;}
1841 template <class _Fp>
1842 inline _LIBCPP_INLINE_VISIBILITY
1844 operator==(nullptr_t, const function<_Fp>& __f) {return !__f;}
1846 template <class _Fp>
1847 inline _LIBCPP_INLINE_VISIBILITY
1849 operator!=(const function<_Fp>& __f, nullptr_t) {return (bool)__f;}
1851 template <class _Fp>
1852 inline _LIBCPP_INLINE_VISIBILITY
1854 operator!=(nullptr_t, const function<_Fp>& __f) {return (bool)__f;}
1856 template <class _Fp>
1857 inline _LIBCPP_INLINE_VISIBILITY
1859 swap(function<_Fp>& __x, function<_Fp>& __y)
1860 {return __x.swap(__y);}
1862 template<class _Tp> struct __is_bind_expression : public false_type {};
1863 template<class _Tp> struct _LIBCPP_TYPE_VIS is_bind_expression
1864 : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
1866 template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
1867 template<class _Tp> struct _LIBCPP_TYPE_VIS is_placeholder
1868 : public __is_placeholder<typename remove_cv<_Tp>::type> {};
1870 namespace placeholders
1873 template <int _Np> struct __ph {};
1884 extern __ph<10> _10;
1889 struct __is_placeholder<placeholders::__ph<_Np> >
1890 : public integral_constant<int, _Np> {};
1892 template <class _Tp, class _Uj>
1893 inline _LIBCPP_INLINE_VISIBILITY
1895 __mu(reference_wrapper<_Tp> __t, _Uj&)
1900 template <bool _IsBindExpr, class _Ti, class ..._Uj>
1901 struct __mu_return1 {};
1903 template <class _Ti, class ..._Uj>
1904 struct __mu_return1<true, _Ti, _Uj...>
1906 typedef typename result_of<_Ti(_Uj...)>::type type;
1909 template <class _Ti, class ..._Uj, size_t ..._Indx>
1910 inline _LIBCPP_INLINE_VISIBILITY
1911 typename __mu_return1<true, _Ti, _Uj...>::type
1912 __mu_expand(_Ti& __ti, tuple<_Uj...>&& __uj, __tuple_indices<_Indx...>)
1914 __ti(_VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(get<_Indx>(__uj))...);
1917 template <class _Ti, class ..._Uj>
1918 inline _LIBCPP_INLINE_VISIBILITY
1921 is_bind_expression<_Ti>::value,
1922 typename __mu_return1<is_bind_expression<_Ti>::value, _Ti, _Uj...>::type
1924 __mu(_Ti& __ti, tuple<_Uj...>& __uj)
1926 typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
1927 return __mu_expand(__ti, __uj, __indices());
1930 template <bool IsPh, class _Ti, class _Uj>
1931 struct __mu_return2 {};
1933 template <class _Ti, class _Uj>
1934 struct __mu_return2<true, _Ti, _Uj>
1936 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
1939 template <class _Ti, class _Uj>
1940 inline _LIBCPP_INLINE_VISIBILITY
1943 0 < is_placeholder<_Ti>::value,
1944 typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
1946 __mu(_Ti&, _Uj& __uj)
1948 const size_t _Indx = is_placeholder<_Ti>::value - 1;
1949 // compiler bug workaround
1950 typename tuple_element<_Indx, _Uj>::type __t = get<_Indx>(__uj);
1952 // return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(get<_Indx>(__uj));
1955 template <class _Ti, class _Uj>
1956 inline _LIBCPP_INLINE_VISIBILITY
1959 !is_bind_expression<_Ti>::value &&
1960 is_placeholder<_Ti>::value == 0 &&
1961 !__is_reference_wrapper<_Ti>::value,
1964 __mu(_Ti& __ti, _Uj& __uj)
1969 template <class _Ti, bool IsBindEx, bool IsPh, class _TupleUj>
1970 struct ____mu_return;
1972 template <class _Ti, class ..._Uj>
1973 struct ____mu_return<_Ti, true, false, tuple<_Uj...> >
1975 typedef typename result_of<_Ti(_Uj...)>::type type;
1978 template <class _Ti, class _TupleUj>
1979 struct ____mu_return<_Ti, false, true, _TupleUj>
1981 typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
1982 _TupleUj>::type&& type;
1985 template <class _Ti, class _TupleUj>
1986 struct ____mu_return<_Ti, false, false, _TupleUj>
1991 template <class _Ti, class _TupleUj>
1993 : public ____mu_return<_Ti,
1994 is_bind_expression<_Ti>::value,
1995 0 < is_placeholder<_Ti>::value,
2000 template <class _Ti, class _TupleUj>
2001 struct __mu_return<reference_wrapper<_Ti>, _TupleUj>
2006 template <class _Fp, class _BoundArgs, class _TupleUj>
2007 struct __bind_return;
2009 template <class _Fp, class ..._BoundArgs, class _TupleUj>
2010 struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
2012 typedef typename __ref_return
2015 typename __mu_return
2023 template <class _Fp, class ..._BoundArgs, class _TupleUj>
2024 struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
2026 typedef typename __ref_return
2029 typename __mu_return
2037 template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
2038 inline _LIBCPP_INLINE_VISIBILITY
2039 typename __bind_return<_Fp, _BoundArgs, _Args>::type
2040 __apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
2043 return __invoke(__f, __mu(get<_Indx>(__bound_args), __args)...);
2046 template<class _Fp, class ..._BoundArgs>
2050 tuple<_BoundArgs...> __bound_args_;
2052 typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
2054 template <class _Gp, class ..._BA>
2055 explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
2056 : __f_(_VSTD::forward<_Gp>(__f)),
2057 __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
2059 template <class ..._Args>
2060 typename __bind_return<_Fp, tuple<_BoundArgs...>, tuple<_Args&&...> >::type
2061 operator()(_Args&& ...__args)
2063 // compiler bug workaround
2064 return __apply_functor(__f_, __bound_args_, __indices(),
2065 tuple<_Args&&...>(__args...));
2068 template <class ..._Args>
2069 typename __bind_return<_Fp, tuple<_BoundArgs...>, tuple<_Args&&...> >::type
2070 operator()(_Args&& ...__args) const
2072 return __apply_functor(__f_, __bound_args_, __indices(),
2073 tuple<_Args&&...>(__args...));
2077 template<class _Fp, class ..._BoundArgs>
2078 struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
2080 template<class _Rp, class _Fp, class ..._BoundArgs>
2082 : public __bind<_Fp, _BoundArgs...>
2084 typedef __bind<_Fp, _BoundArgs...> base;
2086 typedef _Rp result_type;
2088 template <class _Gp, class ..._BA>
2089 explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
2090 : base(_VSTD::forward<_Gp>(__f),
2091 _VSTD::forward<_BA>(__bound_args)...) {}
2093 template <class ..._Args>
2095 operator()(_Args&& ...__args)
2097 return base::operator()(_VSTD::forward<_Args>(__args)...);
2100 template <class ..._Args>
2102 operator()(_Args&& ...__args) const
2104 return base::operator()(_VSTD::forward<_Args>(__args)...);
2108 template<class _Rp, class _Fp, class ..._BoundArgs>
2109 struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
2111 template<class _Fp, class ..._BoundArgs>
2112 inline _LIBCPP_INLINE_VISIBILITY
2113 __bind<typename decay<_Fp>::type, typename decay<_BoundArgs>::type...>
2114 bind(_Fp&& __f, _BoundArgs&&... __bound_args)
2116 typedef __bind<typename decay<_Fp>::type, typename decay<_BoundArgs>::type...> type;
2117 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
2120 template<class _Rp, class _Fp, class ..._BoundArgs>
2121 inline _LIBCPP_INLINE_VISIBILITY
2122 __bind_r<_Rp, typename decay<_Fp>::type, typename decay<_BoundArgs>::type...>
2123 bind(_Fp&& __f, _BoundArgs&&... __bound_args)
2125 typedef __bind_r<_Rp, typename decay<_Fp>::type, typename decay<_BoundArgs>::type...> type;
2126 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
2130 #endif // _LIBCPP_FUNCTIONAL_03