[func.wrap.ref] (original) (raw)
22 General utilities library [utilities]
22.10 Function objects [function.objects]
22.10.17 Polymorphic function wrappers [func.wrap]
22.10.17.6 Non-owning wrapper [func.wrap.ref]
22.10.17.6.1 General [func.wrap.ref.general]
22.10.17.6.2 Class template function_ref [func.wrap.ref.class]
22.10.17.6.3 Constructors and assignment operators [func.wrap.ref.ctor]
22.10.17.6.4 Invocation [func.wrap.ref.inv]
22.10.17.6.5 Deduction guides [func.wrap.ref.deduct]
22.10.17.6.1 General [func.wrap.ref.general]
The header provides partial specializations of function_reffor each combination of the possible replacements of the placeholders cv and noex where:
- cv is either const or empty, and
- noex is either true or false.
22.10.17.6.2 Class template function_ref [func.wrap.ref.class]
namespace std { template<class R, class... ArgTypes> class function_ref<R(ArgTypes...) cv noexcept(_noex_)> { public: template<class F> function_ref(F*) noexcept;template<class F> constexpr function_ref(F&&) noexcept;template<auto f> constexpr function_ref(nontype_t<f>) noexcept;template<auto f, class U> constexpr function_ref(nontype_t<f>, U&&) noexcept;template<auto f, class T> constexpr function_ref(nontype_t<f>, cv T*) noexcept;constexpr function_ref(const function_ref&) noexcept = default;constexpr function_ref& operator=(const function_ref&) noexcept = default;template<class T> function_ref& operator=(T) = delete; R operator()(ArgTypes...) const noexcept(noex);private: template<class... T> static constexpr bool is-invocable-using = see below; R (*thunk-ptr)(BoundEntityType, ArgTypes&&...) noexcept(noex); BoundEntityType bound-entity; };template<class F> function_ref(F*) -> function_ref<F>;template<auto f> function_ref(nontype_t<f>) -> function_ref<_see below_>;template<auto f, class T> function_ref(nontype_t<f>, T&&) -> function_ref<_see below_>;}
An object of classfunction_ref<R(Args...) cv noexcept(_noex_)>stores a pointer to function thunk-ptr and an object bound-entity.
The object bound-entity has an unspecified trivially copyable type BoundEntityType, that models copyable and is capable of storing a pointer to object value or a pointer to function value.
The type of thunk-ptr isR(*)(BoundEntityType, Args&&...) noexcept(noex).
Within subclause [func.wrap.ref],call-args is an argument pack with elements such thatdecltype((call-args))... denote ArgTypes&&... respectively.
22.10.17.6.3 Constructors and assignment operators [func.wrap.ref.ctor]
template<class... T> static constexpr bool _is-invocable-using_ = _see below_;
If noex is true,is-invocable-using<T...> is equal to:is_nothrow_invocable_r_v<R, T..., ArgTypes...>
Otherwise, is-invocable-using<T...> is equal to:is_invocable_r_v<R, T..., ArgTypes...>
template<class F> function_ref(F* f) noexcept;
Constraints:
- is_function_v<F> is true, and
- is-invocable-using<F> is true.
Preconditions: f is not a null pointer.
Effects: Initializes_bound-entity_ with f, and_thunk-ptr_ with the address of a function thunk_such that_thunk(bound-entity, call-args...)is expression-equivalent ([defns.expression.equivalent]) toinvoke_r<R>(f, call-args...).
template<class F> constexpr function_ref(F&& f) noexcept;
Let T be remove_reference_t<F>.
Constraints:
- remove_cvref_t<F> is not the same type as function_ref,
- is_member_pointer_v<T> is false, and
- is-invocable-using<cv T&> is true.
Effects: Initializes_bound-entity_ with addressof(f), and_thunk-ptr_ with the address of a function thunk_such that_thunk(bound-entity, call-args...)is expression-equivalent ([defns.expression.equivalent]) toinvoke_r<R>(static_cast<cv T&>(f), call-args...).
template<auto f> constexpr function_ref(nontype_t<f>) noexcept;
Constraints: is-invocable-using<F> is true.
Mandates: If is_pointer_v<F> || is_member_pointer_v<F> is true, then f != nullptr is true.
Effects: Initializes_bound-entity_ with a pointer to an unspecified object or null pointer value, and_thunk-ptr_ with the address of a function thunk_such that_thunk(bound-entity, call-args...)is expression-equivalent ([defns.expression.equivalent]) toinvoke_r<R>(f, call-args...).
template<auto f, class U> constexpr function_ref(nontype_t<f>, U&& obj) noexcept;
Let T be remove_reference_t<U> andF be decltype(f).
Constraints:
- is_rvalue_reference_v<U&&> is false, and
- is-invocable-using<F, cv T&> is true.
Mandates: If is_pointer_v<F> || is_member_pointer_v<F> is true, then f != nullptr is true.
Effects: Initializes_bound-entity_ with addressof(obj), and_thunk-ptr_ with the address of a function thunk_such that_thunk(bound-entity, call-args...)is expression-equivalent ([defns.expression.equivalent]) toinvoke_r<R>(f, static_cast<cv T&>(obj), call-args...).
template<auto f, class T> constexpr function_ref(nontype_t<f>, cv T* obj) noexcept;
Constraints: is-invocable-using<F, cv T*> is true.
Mandates: If is_pointer_v<F> || is_member_pointer_v<F> is true, then f != nullptr is true.
Preconditions: If is_member_pointer_v<F> is true,obj is not a null pointer.
Effects: Initializes_bound-entity_ with obj, and_thunk-ptr_ with the address of a function thunk_such that_thunk(bound-entity, call-args...)is expression-equivalent ([defns.expression.equivalent]) toinvoke_r<R>(f, obj, call-args...).
template<class T> function_ref& operator=(T) = delete;
Constraints:
- T is not the same type as function_ref,
- is_pointer_v<T> is false, and
- T is not a specialization of nontype_t.
22.10.17.6.4 Invocation [func.wrap.ref.inv]
R operator()(ArgTypes... args) const noexcept(_noex_);
Effects: Equivalent to:return thunk-ptr(bound-entity, std::forward<ArgTypes>(args)...);
22.10.17.6.5 Deduction guides [func.wrap.ref.deduct]
template<class F> function_ref(F*) -> function_ref<F>;
Constraints: is_function_v<F> is true.
template<auto f> function_ref(nontype_t<f>) -> function_ref<_see below_>;
Let F be remove_pointer_t<decltype(f)>.
Constraints: is_function_v<F> is true.
Remarks: The deduced type is function_ref<F>.
template<auto f, class T> function_ref(nontype_t<f>, T&&) -> function_ref<_see below_>;
Constraints:
- F is of the formR(G::*)(A...) cv & noexcept(E) for a type G, or
- F is of the formM G::* for a type G and an object type M, in which case let R be invoke_result_t<F, T&>,A... be an empty pack, andE be false, or
- F is of the formR(*)(G, A...) noexcept(E) for a type G.
Remarks: The deduced type is function_ref<R(A...) noexcept(E)>.