30#ifndef _GLIBCXX_STD_FUNCTION_H
31#define _GLIBCXX_STD_FUNCTION_H 1
33#pragma GCC system_header
35#if __cplusplus < 201103L
47namespace std _GLIBCXX_VISIBILITY(default)
49_GLIBCXX_BEGIN_NAMESPACE_VERSION
72 : is_trivially_copyable<_Tp>::type
80 const void* _M_const_object;
81 void (*_M_function_pointer)();
85 union [[gnu::may_alias]] _Any_data
87 void* _M_access() {
return &_M_pod_data[0]; }
88 const void* _M_access()
const {
return &_M_pod_data[0]; }
90 template<
typename _Tp>
93 {
return *
static_cast<_Tp*
>(_M_access()); }
95 template<
typename _Tp>
98 {
return *
static_cast<const _Tp*
>(_M_access()); }
100 _Nocopy_types _M_unused;
101 char _M_pod_data[
sizeof(_Nocopy_types)];
104 enum _Manager_operation
112 template<
typename _Signature>
119 static const size_t _M_max_size =
sizeof(_Nocopy_types);
120 static const size_t _M_max_align =
__alignof__(_Nocopy_types);
122 template<
typename _Functor>
126 static const bool __stored_locally =
128 &&
sizeof(_Functor) <= _M_max_size
136 _M_get_pointer(
const _Any_data&
__source)
140 const _Functor& __f =
__source._M_access<_Functor>();
144 return __source._M_access<_Functor*>();
152 ::new (
__dest._M_access()) _Functor(
__source._M_access<_Functor>());
160 __dest._M_access<_Functor*>() =
161 new _Functor(*
__source._M_access<
const _Functor*>());
169 __victim._M_access<_Functor>().~_Functor();
176 delete __victim._M_access<_Functor*>();
182 _Manager_operation
__op)
187 case __get_type_info:
191 case __get_functor_ptr:
195 case __clone_functor:
199 case __destroy_functor:
200 _M_destroy(
__dest, _Local_storage());
207 _M_init_functor(_Any_data&
__functor, _Functor&& __f)
210 template<
typename _Signature>
213 {
return static_cast<bool>(__f); }
215 template<
typename _Tp>
217 _M_not_empty_function(_Tp*
__fp)
218 {
return __fp !=
nullptr; }
220 template<
typename _Class,
typename _Tp>
222 _M_not_empty_function(_Tp _Class::*
__mp)
223 {
return __mp !=
nullptr; }
225 template<
typename _Tp>
227 _M_not_empty_function(
const _Tp&)
245 _M_manager(_M_functor, _M_functor, __destroy_functor);
248 bool _M_empty()
const {
return !_M_manager; }
250 typedef bool (*_Manager_type)(_Any_data&,
const _Any_data&,
253 _Any_data _M_functor;
254 _Manager_type _M_manager;
257 template<
typename _Signature,
typename _Functor>
258 class _Function_handler;
260 template<
typename _Res,
typename _Functor,
typename...
_ArgTypes>
262 :
public _Function_base::_Base_manager<_Functor>
264 typedef _Function_base::_Base_manager<_Functor> _Base;
269 _Manager_operation
__op)
274 case __get_type_info:
278 case __get_functor_ptr:
289 _M_invoke(
const _Any_data& __functor, _ArgTypes&&... __args)
302 template<
typename _Res,
typename... _ArgTypes>
304 :
public _Maybe_unary_or_binary_function<_Res, _ArgTypes...>,
307 template<
typename _Func,
315 template<
typename _Tp>
318 template<
typename _Cond,
typename _Tp>
348 function(
const function& __x);
378 template<
typename _Functor,
398 function(__x).swap(*
this);
432 _M_manager(_M_functor, _M_functor, __destroy_functor);
433 _M_manager =
nullptr;
434 _M_invoker =
nullptr;
455 template<
typename _Functor>
464 template<
typename _Functor>
468 function(__f).swap(*
this);
481 void swap(function& __x)
noexcept
483 std::swap(_M_functor, __x._M_functor);
484 std::swap(_M_manager, __x._M_manager);
485 std::swap(_M_invoker, __x._M_invoker);
499 {
return !_M_empty(); }
544 using _Invoker_type =
_Res (*)(
const _Any_data&,
_ArgTypes&&...);
545 _Invoker_type _M_invoker;
548#if __cpp_deduction_guides >= 201606
550 struct __function_guide_helper
553 template<
typename _Res,
typename _Tp,
bool _Nx,
typename... _Args>
554 struct __function_guide_helper<
555 _Res (_Tp::*) (_Args...) noexcept(_Nx)
557 {
using type = _Res(_Args...); };
559 template<
typename _Res,
typename _Tp,
bool _Nx,
typename... _Args>
560 struct __function_guide_helper<
561 _Res (_Tp::*) (_Args...) & noexcept(_Nx)
563 {
using type = _Res(_Args...); };
565 template<
typename _Res,
typename _Tp,
bool _Nx,
typename... _Args>
566 struct __function_guide_helper<
567 _Res (_Tp::*) (_Args...) const noexcept(_Nx)
569 {
using type = _Res(_Args...); };
571 template<
typename _Res,
typename _Tp,
bool _Nx,
typename... _Args>
572 struct __function_guide_helper<
573 _Res (_Tp::*) (_Args...) const & noexcept(_Nx)
575 {
using type = _Res(_Args...); };
577 template<
typename _Res,
typename... _ArgTypes>
578 function(_Res(*)(_ArgTypes...)) -> function<_Res(_ArgTypes...)>;
580 template<
typename _Functor,
typename _Signature =
typename
581 __function_guide_helper<
decltype(&_Functor::operator())>::type>
582 function(_Functor) -> function<_Signature>;
586 template<
typename _Res,
typename... _ArgTypes>
588 function(
const function& __x)
591 if (
static_cast<bool>(__x))
593 __x._M_manager(_M_functor, __x._M_functor, __clone_functor);
594 _M_invoker = __x._M_invoker;
595 _M_manager = __x._M_manager;
600 template<
typename _Functor,
typename,
typename>
602 function(_Functor __f)
607 if (_My_handler::_M_not_empty_function(__f))
609 _My_handler::_M_init_functor(_M_functor,
std::move(__f));
610 _M_invoker = &_My_handler::_M_invoke;
611 _M_manager = &_My_handler::_M_manager;
621 __throw_bad_function_call();
642 template<
typename _Functor>
649 return const_cast<_Functor*
>(
__func);
653 template<
typename _Functor>
658 if (
typeid(_Functor) == target_type() && _M_manager)
661 _M_manager(
__ptr, _M_functor, __get_functor_ptr);
662 return __ptr._M_access<
const _Functor*>();
678 template<
typename _Res,
typename...
_Args>
680 operator==(
const function<
_Res(
_Args...)>& __f, nullptr_t)
noexcept
681 {
return !
static_cast<bool>(__f); }
683#if __cpp_impl_three_way_comparison < 201907L
685 template<
typename _Res,
typename... _Args>
687 operator==(nullptr_t,
const function<
_Res(
_Args...)>& __f)
noexcept
688 {
return !
static_cast<bool>(__f); }
697 template<
typename _Res,
typename... _Args>
699 operator!=(
const function<
_Res(
_Args...)>& __f, nullptr_t)
noexcept
700 {
return static_cast<bool>(__f); }
703 template<
typename _Res,
typename... _Args>
705 operator!=(nullptr_t,
const function<
_Res(
_Args...)>& __f)
noexcept
706 {
return static_cast<bool>(__f); }
718 template<
typename _Res,
typename... _Args>
723#if __cplusplus >= 201703L
724 namespace __detail::__variant
726 template<
typename>
struct _Never_valueless_alt;
730 template<
typename _Signature>
731 struct _Never_valueless_alt<
std::function<_Signature>>
737_GLIBCXX_END_NAMESPACE_VERSION
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
ISO C++ entities toplevel namespace is std.
Define a member typedef type only if a boolean constant is true.
Base class for all library exceptions.
Exception class thrown when class template function's operator() is called with an empty target.
const char * what() const noexcept
Base class of all polymorphic function object wrappers.
function & operator=(const function &__x)
Function assignment operator.
function(nullptr_t) noexcept
Creates an empty function call wrapper.
function & operator=(reference_wrapper< _Functor > __f) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
function & operator=(function &&__x) noexcept
Function move-assignment operator.
function(function &&__x) noexcept
Function move constructor.
function & operator=(nullptr_t) noexcept
Function assignment to zero.
function() noexcept
Default construct creates an empty function call wrapper.
_Requires< _Callable< typename decay< _Functor >::type >, function & > operator=(_Functor &&__f)
Function assignment to a new target.
void swap(function &__x) noexcept
Swap the targets of two function objects.