libstdc++: std_function.h Source File

libstdc++

std_function.h
Go to the documentation of this file.
1// Implementation of std::function -*- C++ -*-
2
3// Copyright (C) 2004-2026 Free Software Foundation, Inc.
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
19
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
24
25/** @file include/bits/std_function.h
26 * This is an internal header file, included by other library headers.
27 * Do not attempt to use it directly. @headername{functional}
28 */
29
30#ifndef _GLIBCXX_STD_FUNCTION_H
31#define _GLIBCXX_STD_FUNCTION_H 1
32
33#ifdef _GLIBCXX_SYSHDR
34#pragma GCC system_header
35#endif
36
37#if __cplusplus < 201103L
38# include <bits/c++0x_warning.h>
39#else
40
41#include <new> // placement new
42#include <typeinfo> // typeid
43#include <bits/invoke.h> // __invoke_r
44#include <bits/refwrap.h> // ref wrapper, _Maybe_unary_or_binary_function
45#include <bits/functexcept.h> // __throw_bad_function_call
46
47namespace std _GLIBCXX_VISIBILITY(default)
48{
49_GLIBCXX_BEGIN_NAMESPACE_VERSION
50
51 /**
52 * @brief Exception class thrown when class template function's
53 * operator() is called with an empty target.
54 * @ingroup exceptions
55 */
56 class bad_function_call : public std::exception
57 {
58 public:
59 virtual ~bad_function_call() noexcept;
60
61 const char* what() const noexcept;
62 };
63
64 /**
65 * Trait identifying "location-invariant" types, meaning that the
66 * address of the object (or any of its members) will not escape.
67 * Trivially copyable types are location-invariant and users can
68 * specialize this trait for other types.
69 */
70 template<typename _Tp>
71 struct __is_location_invariant
72 : is_trivially_copyable<_Tp>::type
73 { };
74
75 class _Undefined_class;
76
77 union _Nocopy_types
78 {
79 void* _M_object;
80 const void* _M_const_object;
81 void (*_M_function_pointer)();
82 void (_Undefined_class::*_M_member_pointer)();
83 };
84
85 union [[gnu::may_alias]] _Any_data
86 {
87 void* _M_access() noexcept { return &_M_pod_data[0]; }
88 const void* _M_access() const noexcept { return &_M_pod_data[0]; }
89
90 template<typename _Tp>
91 _Tp&
92 _M_access() noexcept
93 { return *static_cast<_Tp*>(_M_access()); }
94
95 template<typename _Tp>
96 const _Tp&
97 _M_access() const noexcept
98 { return *static_cast<const _Tp*>(_M_access()); }
99
100 _Nocopy_types _M_unused;
101 char _M_pod_data[sizeof(_Nocopy_types)];
102 };
103
104 enum _Manager_operation
105 {
106 __get_type_info,
107 __get_functor_ptr,
108 __clone_functor,
109 __destroy_functor
110 };
111
112 template<typename _Signature>
113 class function;
114
115 /// Base class of all polymorphic function object wrappers.
116 class _Function_base
117 {
118 public:
119 static const size_t _M_max_size = sizeof(_Nocopy_types);
120 static const size_t _M_max_align = __alignof__(_Nocopy_types);
121
122 template<typename _Functor>
123 class _Base_manager
124 {
125 protected:
126 static const bool __stored_locally =
127 (__is_location_invariant<_Functor>::value
128 && sizeof(_Functor) <= _M_max_size
129 && __alignof__(_Functor) <= _M_max_align
130 && (_M_max_align % __alignof__(_Functor) == 0));
131
132 using _Local_storage = integral_constant<bool, __stored_locally>;
133
134 // Retrieve a pointer to the function object
135 static _Functor*
136 _M_get_pointer(const _Any_data& __source) noexcept
137 {
138#pragma GCC diagnostic push
139#pragma GCC diagnostic ignored "-Wc++17-extensions" // if constexpr
140 if constexpr (__stored_locally)
141 {
142 const _Functor& __f = __source._M_access<_Functor>();
143 return const_cast<_Functor*>(std::__addressof(__f));
144 }
145 else // have stored a pointer
146 return __source._M_access<_Functor*>();
147#pragma GCC diagnostic pop
148 }
149
150 private:
151 // Construct a location-invariant function object that fits within
152 // an _Any_data structure.
153 template<typename _Fn>
154 static void
155 _M_create(_Any_data& __dest, _Fn&& __f, true_type)
156 {
157 ::new (__dest._M_access()) _Functor(std::forward<_Fn>(__f));
158 }
159
160 // Construct a function object on the heap and store a pointer.
161 template<typename _Fn>
162 static void
163 _M_create(_Any_data& __dest, _Fn&& __f, false_type)
164 {
165 __dest._M_access<_Functor*>()
166 = new _Functor(std::forward<_Fn>(__f));
167 }
168
169 // Destroy an object stored in the internal buffer.
170 static void
171 _M_destroy(_Any_data& __victim, true_type)
172 {
173 __victim._M_access<_Functor>().~_Functor();
174 }
175
176 // Destroy an object located on the heap.
177 static void
178 _M_destroy(_Any_data& __victim, false_type)
179 {
180 delete __victim._M_access<_Functor*>();
181 }
182
183 public:
184 static bool
185 _M_manager(_Any_data& __dest, const _Any_data& __source,
186 _Manager_operation __op)
187 {
188 switch (__op)
189 {
190 case __get_type_info:
191#if __cpp_rtti
192 __dest._M_access<const type_info*>() = &typeid(_Functor);
193#else
194 __dest._M_access<const type_info*>() = nullptr;
195#endif
196 break;
197
198 case __get_functor_ptr:
199 __dest._M_access<_Functor*>() = _M_get_pointer(__source);
200 break;
201
202 case __clone_functor:
203 _M_init_functor(__dest,
204 *const_cast<const _Functor*>(_M_get_pointer(__source)));
205 break;
206
207 case __destroy_functor:
208 _M_destroy(__dest, _Local_storage());
209 break;
210 }
211 return false;
212 }
213
214 template<typename _Fn>
215 static void
216 _M_init_functor(_Any_data& __functor, _Fn&& __f)
217 noexcept(__and_<_Local_storage,
218 is_nothrow_constructible<_Functor, _Fn>>::value)
219 {
220 _M_create(__functor, std::forward<_Fn>(__f), _Local_storage());
221 }
222
223 template<typename _Signature>
224 static bool
225 _M_not_empty_function(const function<_Signature>& __f) noexcept
226 { return static_cast<bool>(__f); }
227
228 template<typename _Tp>
229 static bool
230 _M_not_empty_function(_Tp* __fp) noexcept
231 { return __fp != nullptr; }
232
233 template<typename _Class, typename _Tp>
234 static bool
235 _M_not_empty_function(_Tp _Class::* __mp) noexcept
236 { return __mp != nullptr; }
237
238 template<typename _Tp>
239 static bool
240 _M_not_empty_function(const _Tp&) noexcept
241 { return true; }
242 };
243
244 _Function_base() = default;
245
246 ~_Function_base()
247 {
248 if (_M_manager)
249 _M_manager(_M_functor, _M_functor, __destroy_functor);
250 }
251
252 bool _M_empty() const { return !_M_manager; }
253
254 using _Manager_type
255 = bool (*)(_Any_data&, const _Any_data&, _Manager_operation);
256
257 _Any_data _M_functor{};
258 _Manager_type _M_manager{};
259 };
260
261 template<typename _Signature, typename _Functor>
262 class _Function_handler;
263
264 template<typename _Res, typename _Functor, typename... _ArgTypes>
265 class _Function_handler<_Res(_ArgTypes...), _Functor>
266 : public _Function_base::_Base_manager<_Functor>
267 {
268 using _Base = _Function_base::_Base_manager<_Functor>;
269
270 public:
271 static bool
272 _M_manager(_Any_data& __dest, const _Any_data& __source,
273 _Manager_operation __op)
274 {
275 switch (__op)
276 {
277#if __cpp_rtti
278 case __get_type_info:
279 __dest._M_access<const type_info*>() = &typeid(_Functor);
280 break;
281#endif
282 case __get_functor_ptr:
283 __dest._M_access<_Functor*>() = _Base::_M_get_pointer(__source);
284 break;
285
286 default:
287 _Base::_M_manager(__dest, __source, __op);
288 }
289 return false;
290 }
291
292 static _Res
293 _M_invoke(const _Any_data& __functor, _ArgTypes&&... __args)
294 {
295 return std::__invoke_r<_Res>(*_Base::_M_get_pointer(__functor),
296 std::forward<_ArgTypes>(__args)...);
297 }
298
299 template<typename _Fn>
300 static constexpr bool
301 _S_nothrow_init() noexcept
302 {
303 return __and_<typename _Base::_Local_storage,
304 is_nothrow_constructible<_Functor, _Fn>>::value;
305 }
306 };
307
308 // Specialization for invalid types
309 template<>
310 class _Function_handler<void, void>
311 {
312 public:
313 static bool
314 _M_manager(_Any_data&, const _Any_data&, _Manager_operation)
315 { return false; }
316 };
317
318 /**
319 * @brief Polymorphic function wrapper.
320 * @ingroup functors
321 * @since C++11
322 */
323 template<typename _Res, typename... _ArgTypes>
324 class function<_Res(_ArgTypes...)>
325 : public _Maybe_unary_or_binary_function<_Res, _ArgTypes...>,
326 private _Function_base
327 {
328 // Equivalent to std::decay_t except that it produces an invalid type
329 // if the decayed type is the current specialization of std::function.
330 template<typename _Func,
331 bool _Self = is_same<__remove_cvref_t<_Func>, function>::value>
332 using _Decay_t
333 = typename __enable_if_t<!_Self, decay<_Func>>::type;
334
335 template<typename _Func,
336 typename _DFunc = _Decay_t<_Func>,
337 typename _Res2 = __invoke_result<_DFunc&, _ArgTypes...>>
338 struct _Callable
339 : __is_invocable_impl<_Res2, _Res>::type
340 { };
341
342 template<typename _Cond, typename _Tp = void>
343 using _Requires = __enable_if_t<_Cond::value, _Tp>;
344
345 template<typename _Functor>
346 using _Handler
347 = _Function_handler<_Res(_ArgTypes...), __decay_t<_Functor>>;
348
349 public:
350 typedef _Res result_type;
351
352 // [3.7.2.1] construct/copy/destroy
353
354 /**
355 * @brief Default construct creates an empty function call wrapper.
356 * @post `!(bool)*this`
357 */
358 function() noexcept
359 : _Function_base() { }
360
361 /**
362 * @brief Creates an empty function call wrapper.
363 * @post @c !(bool)*this
364 */
365 function(nullptr_t) noexcept
366 : _Function_base() { }
367
368 /**
369 * @brief %Function copy constructor.
370 * @param __x A %function object with identical call signature.
371 * @post `bool(*this) == bool(__x)`
372 *
373 * The newly-created %function contains a copy of the target of
374 * `__x` (if it has one).
375 */
376 function(const function& __x)
377 : _Function_base()
378 {
379 if (static_cast<bool>(__x))
380 {
381 __x._M_manager(_M_functor, __x._M_functor, __clone_functor);
382 _M_invoker = __x._M_invoker;
383 _M_manager = __x._M_manager;
384 }
385 }
386
387 /**
388 * @brief %Function move constructor.
389 * @param __x A %function object rvalue with identical call signature.
390 *
391 * The newly-created %function contains the target of `__x`
392 * (if it has one).
393 */
394 function(function&& __x) noexcept
395 : _Function_base(), _M_invoker(__x._M_invoker)
396 {
397 if (static_cast<bool>(__x))
398 {
399 _M_functor = __x._M_functor;
400 _M_manager = __x._M_manager;
401 __x._M_manager = nullptr;
402 __x._M_invoker = nullptr;
403 }
404 }
405
406 /**
407 * @brief Builds a %function that targets a copy of the incoming
408 * function object.
409 * @param __f A %function object that is callable with parameters of
410 * type `ArgTypes...` and returns a value convertible to `Res`.
411 *
412 * The newly-created %function object will target a copy of
413 * `__f`. If `__f` is `reference_wrapper<F>`, then this function
414 * object will contain a reference to the function object `__f.get()`.
415 * If `__f` is a null function pointer, null pointer-to-member, or
416 * empty `std::function`, the newly-created object will be empty.
417 *
418 * If `__f` is a non-null function pointer or an object of type
419 * `reference_wrapper<F>`, this function will not throw.
420 */
421 // _GLIBCXX_RESOLVE_LIB_DEFECTS
422 // 2774. std::function construction vs assignment
423 template<typename _Functor,
424 typename _Constraints = _Requires<_Callable<_Functor>>>
425 function(_Functor&& __f)
426 noexcept(_Handler<_Functor>::template _S_nothrow_init<_Functor>())
427 : _Function_base()
428 {
429 static_assert(is_copy_constructible<__decay_t<_Functor>>::value,
430 "std::function target must be copy-constructible");
431 static_assert(is_constructible<__decay_t<_Functor>, _Functor>::value,
432 "std::function target must be constructible from the "
433 "constructor argument");
434
435 using _My_handler = _Handler<_Functor>;
436
437 if (_My_handler::_M_not_empty_function(__f))
438 {
439 _My_handler::_M_init_functor(_M_functor,
440 std::forward<_Functor>(__f));
441 _M_invoker = &_My_handler::_M_invoke;
442 _M_manager = &_My_handler::_M_manager;
443 }
444 }
445
446 /**
447 * @brief Function assignment operator.
448 * @param __x A %function with identical call signature.
449 * @post `(bool)*this == (bool)x`
450 * @returns `*this`
451 *
452 * The target of `__x` is copied to `*this`. If `__x` has no
453 * target, then `*this` will be empty.
454 *
455 * If `__x` targets a function pointer or a reference to a function
456 * object, then this operation will not throw an exception.
457 */
458 function&
459 operator=(const function& __x)
460 {
461 function(__x).swap(*this);
462 return *this;
463 }
464
465 /**
466 * @brief Function move-assignment operator.
467 * @param __x A %function rvalue with identical call signature.
468 * @returns `*this`
469 *
470 * The target of `__x` is moved to `*this`. If `__x` has no
471 * target, then `*this` will be empty.
472 *
473 * If `__x` targets a function pointer or a reference to a function
474 * object, then this operation will not throw an exception.
475 */
476 function&
477 operator=(function&& __x) noexcept
478 {
479 function(std::move(__x)).swap(*this);
480 return *this;
481 }
482
483 /**
484 * @brief Function assignment to empty.
485 * @post `!(bool)*this`
486 * @returns `*this`
487 *
488 * The target of `*this` is deallocated, leaving it empty.
489 */
490 function&
491 operator=(nullptr_t) noexcept
492 {
493 if (_M_manager)
494 {
495 _M_manager(_M_functor, _M_functor, __destroy_functor);
496 _M_manager = nullptr;
497 _M_invoker = nullptr;
498 }
499 return *this;
500 }
501
502 /**
503 * @brief Function assignment to a new target.
504 * @param __f A function object that is callable with parameters of
505 * type `_ArgTypes...` and returns a value convertible
506 * to `_Res`.
507 * @return `*this`
508 * @since C++11
509 *
510 * This function object wrapper will target a copy of `__f`. If `__f`
511 * is `reference_wrapper<F>`, then this function object will contain
512 * a reference to the function object `__f.get()`. If `__f` is a null
513 * function pointer or null pointer-to-member, this object will be
514 * empty.
515 *
516 * If `__f` is a non-null function pointer or an object of type
517 * `reference_wrapper<F>`, this function will not throw.
518 */
519 template<typename _Functor>
520 _Requires<_Callable<_Functor>, function&>
521 operator=(_Functor&& __f)
522 noexcept(_Handler<_Functor>::template _S_nothrow_init<_Functor>())
523 {
524 function(std::forward<_Functor>(__f)).swap(*this);
525 return *this;
526 }
527
528 /// @overload
529 template<typename _Functor>
530 function&
531 operator=(reference_wrapper<_Functor> __f) noexcept
532 {
533 function(__f).swap(*this);
534 return *this;
535 }
536
537 // [3.7.2.2] function modifiers
538
539 /**
540 * @brief Swap the targets of two %function objects.
541 * @param __x A %function with identical call signature.
542 *
543 * Swap the targets of `this` function object and `__f`.
544 * This function will not throw exceptions.
545 */
546 void swap(function& __x) noexcept
547 {
548 std::swap(_M_functor, __x._M_functor);
549 std::swap(_M_manager, __x._M_manager);
550 std::swap(_M_invoker, __x._M_invoker);
551 }
552
553 // [3.7.2.3] function capacity
554
555 /**
556 * @brief Determine if the %function wrapper has a target.
557 *
558 * @return `true` when this function object contains a target,
559 * or `false` when it is empty.
560 *
561 * This function will not throw exceptions.
562 */
563 explicit operator bool() const noexcept
564 { return !_M_empty(); }
565
566 // [3.7.2.4] function invocation
567
568 /**
569 * @brief Invokes the function targeted by `*this`.
570 * @returns the result of the target.
571 * @throws `bad_function_call` when `!(bool)*this`
572 *
573 * The function call operator invokes the target function object
574 * stored by `this`.
575 */
576 _Res
577 operator()(_ArgTypes... __args) const
578 {
579 if (_M_empty())
580 __throw_bad_function_call();
581 return _M_invoker(_M_functor, std::forward<_ArgTypes>(__args)...);
582 }
583
584#if __cpp_rtti
585 // [3.7.2.5] function target access
586 /**
587 * @brief Determine the type of the target of this function object
588 * wrapper.
589 *
590 * @returns the type identifier of the target function object, or
591 * `typeid(void)` if `!(bool)*this`.
592 *
593 * This function will not throw exceptions.
594 */
595 const type_info&
596 target_type() const noexcept
597 {
598 if (_M_manager)
599 {
600 _Any_data __typeinfo_result;
601 _M_manager(__typeinfo_result, _M_functor, __get_type_info);
602 if (auto __ti = __typeinfo_result._M_access<const type_info*>())
603 return *__ti;
604 }
605 return typeid(void);
606 }
607#endif
608
609 /**
610 * @brief Access the stored target function object.
611 *
612 * @return Returns a pointer to the stored target function object,
613 * if `typeid(_Functor).equals(target_type())`; otherwise, a null
614 * pointer.
615 *
616 * This function does not throw exceptions.
617 *
618 * @{
619 */
620 template<typename _Functor>
621 _Functor*
622 target() noexcept
623 {
624 const function* __const_this = this;
625 const _Functor* __func = __const_this->template target<_Functor>();
626 // If is_function_v<_Functor> is true then const_cast<_Functor*>
627 // would be ill-formed, so use *const_cast<_Functor**> instead.
628 return *const_cast<_Functor**>(&__func);
629 }
630
631 template<typename _Functor>
632 const _Functor*
633 target() const noexcept
634 {
635#pragma GCC diagnostic push
636#pragma GCC diagnostic ignored "-Wc++17-extensions" // if constexpr
637 if constexpr (is_object<_Functor>::value)
638 {
639 if (_M_manager == &_Handler<_Functor>::_M_manager
640#if __cpp_rtti
641 || (_M_manager && typeid(_Functor) == target_type())
642#endif
643 )
644 {
645 _Any_data __ptr;
646 _M_manager(__ptr, _M_functor, __get_functor_ptr);
647 return __ptr._M_access<const _Functor*>();
648 }
649 }
650#pragma GCC diagnostic pop
651 return nullptr;
652 }
653 /// @}
654
655 private:
656 using _Invoker_type = _Res (*)(const _Any_data&, _ArgTypes&&...);
657 _Invoker_type _M_invoker = nullptr;
658 };
659
660#if __cpp_deduction_guides >= 201606
661 template<typename>
662 struct __function_guide_helper
663 { };
664
665 template<typename _Res, typename _Tp, bool _Nx, typename... _Args>
666 struct __function_guide_helper<
667 _Res (_Tp::*) (_Args...) noexcept(_Nx)
668 >
669 { using type = _Res(_Args...); };
670
671 template<typename _Res, typename _Tp, bool _Nx, typename... _Args>
672 struct __function_guide_helper<
673 _Res (_Tp::*) (_Args...) & noexcept(_Nx)
674 >
675 { using type = _Res(_Args...); };
676
677 template<typename _Res, typename _Tp, bool _Nx, typename... _Args>
678 struct __function_guide_helper<
679 _Res (_Tp::*) (_Args...) const noexcept(_Nx)
680 >
681 { using type = _Res(_Args...); };
682
683 template<typename _Res, typename _Tp, bool _Nx, typename... _Args>
684 struct __function_guide_helper<
685 _Res (_Tp::*) (_Args...) const & noexcept(_Nx)
686 >
687 { using type = _Res(_Args...); };
688
689#if __cpp_explicit_this_parameter >= 202110L
690 // _GLIBCXX_RESOLVE_LIB_DEFECTS
691 // 3617. function/packaged_task deduction guides and deducing this
692 template<typename _Res, typename _Tp, bool _Nx, typename... _Args>
693 struct __function_guide_helper<_Res (*) (_Tp, _Args...) noexcept(_Nx)>
694 { using type = _Res(_Args...); };
695#endif
696
697#if __cpp_static_call_operator >= 202207L && __cpp_concepts >= 202002L
698 template<typename _StaticCallOp>
699 struct __function_guide_static_helper
700 { };
701
702 template<typename _Res, bool _Nx, typename... _Args>
703 struct __function_guide_static_helper<_Res (*) (_Args...) noexcept(_Nx)>
704 { using type = _Res(_Args...); };
705
706 template<typename _Fn, typename _Op>
707 using __function_guide_t = typename __conditional_t<
708 requires (_Fn& __f) { (void) __f.operator(); },
709 __function_guide_static_helper<_Op>,
710 __function_guide_helper<_Op>>::type;
711#else
712 template<typename _Fn, typename _Op>
713 using __function_guide_t = typename __function_guide_helper<_Op>::type;
714#endif
715
716 template<typename _Res, typename... _ArgTypes>
717 function(_Res(*)(_ArgTypes...)) -> function<_Res(_ArgTypes...)>;
718
719 template<typename _Fn, typename _Signature
720 = __function_guide_t<_Fn, decltype(&_Fn::operator())>>
721 function(_Fn) -> function<_Signature>;
722#endif
723
724 // [20.7.15.2.6] null pointer comparisons
725
726 /**
727 * @brief Test whether a polymorphic function object wrapper is empty.
728 * @returns `true` if the wrapper has no target, `false` otherwise
729 *
730 * This function will not throw exceptions.
731 */
732 template<typename _Res, typename... _Args>
733 inline bool
734 operator==(const function<_Res(_Args...)>& __f, nullptr_t) noexcept
735 { return !static_cast<bool>(__f); }
736
737#if __cpp_impl_three_way_comparison < 201907L
738 /// @overload
739 template<typename _Res, typename... _Args>
740 inline bool
741 operator==(nullptr_t, const function<_Res(_Args...)>& __f) noexcept
742 { return !static_cast<bool>(__f); }
743
744 /**
745 * @brief Test whether a polymorphic function object wrapper is non-empty.
746 * @returns `false` if the wrapper has no target, `true` otherwise
747 *
748 * This function will not throw exceptions.
749 */
750 template<typename _Res, typename... _Args>
751 inline bool
752 operator!=(const function<_Res(_Args...)>& __f, nullptr_t) noexcept
753 { return static_cast<bool>(__f); }
754
755 /// @overload
756 template<typename _Res, typename... _Args>
757 inline bool
758 operator!=(nullptr_t, const function<_Res(_Args...)>& __f) noexcept
759 { return static_cast<bool>(__f); }
760#endif
761
762 // [20.7.15.2.7] specialized algorithms
763
764 /**
765 * @brief Swap the targets of two polymorphic function object wrappers.
766 *
767 * This function will not throw exceptions.
768 */
769 // _GLIBCXX_RESOLVE_LIB_DEFECTS
770 // 2062. Effect contradictions w/o no-throw guarantee of std::function swaps
771 template<typename _Res, typename... _Args>
772 inline void
773 swap(function<_Res(_Args...)>& __x, function<_Res(_Args...)>& __y) noexcept
774 { __x.swap(__y); }
775
776#if __cplusplus >= 201703L
777 namespace __detail::__variant
778 {
779 template<typename> struct _Never_valueless_alt; // see <variant>
780
781 // Provide the strong exception-safety guarantee when emplacing a
782 // function into a variant.
783 template<typename _Signature>
784 struct _Never_valueless_alt<std::function<_Signature>>
785 : std::true_type
786 { };
787 } // namespace __detail::__variant
788#endif // C++17
789
790_GLIBCXX_END_NAMESPACE_VERSION
791} // namespace std
792
793#endif // C++11
794#endif // _GLIBCXX_STD_FUNCTION_H
new
typeinfo
c++0x_warning.h
functexcept.h
invoke.h
refwrap.h
std::true_type
__bool_constant< true > true_type
The type used as a compile-time boolean with true value.
Definition type_traits:119
std::false_type
__bool_constant< false > false_type
The type used as a compile-time boolean with false value.
Definition type_traits:122
std::move
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
Definition move.h:138
std::__addressof
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
Definition move.h:52
std::forward
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
Definition move.h:72
std
ISO C++ entities toplevel namespace is std.
std::type_info
Part of RTTI.
Definition typeinfo:94
std::reference_wrapper
Primary class template for reference_wrapper.
Definition refwrap.h:316
std::integral_constant
integral_constant
Definition type_traits:96
std::is_object
is_object
Definition type_traits:857
std::is_same
is_same
Definition type_traits:1626
std::is_trivially_copyable
is_trivially_copyable
Definition type_traits:974
std::is_constructible
is_constructible
Definition type_traits:1242
std::is_copy_constructible
is_copy_constructible
Definition type_traits:1278
std::is_nothrow_constructible
is_nothrow_constructible
Definition type_traits:1320
std::exception
Base class for all library exceptions.
Definition exception.h:62
std::bad_function_call
Exception class thrown when class template function's operator() is called with an empty target.
Definition std_function.h:57
std::bad_function_call::what
const char * what() const noexcept
std::__is_location_invariant
Definition std_function.h:73
std::function< _Res(_ArgTypes...)>::target
_Functor * target() noexcept
Access the stored target function object.
Definition std_function.h:620
std::function< _Res(_ArgTypes...)>::operator=
function & operator=(const function &__x)
Function assignment operator.
Definition std_function.h:457
std::function< _Res(_ArgTypes...)>::target_type
const type_info & target_type() const noexcept
Determine the type of the target of this function object wrapper.
Definition std_function.h:594
std::function< _Res(_ArgTypes...)>::function
function() noexcept
Default construct creates an empty function call wrapper.
Definition std_function.h:356
std::function< _Res(_ArgTypes...)>::operator()
_Res operator()(_ArgTypes... __args) const
Invokes the function targeted by *this.
Definition std_function.h:575
std::function< _Res(_ArgTypes...)>::swap
void swap(function &__x) noexcept
Swap the targets of two function objects.
Definition std_function.h:544