Files
2025-10-25 03:02:53 +03:00

13 KiB
Raw Permalink Blame History

[func.wrap.ref]

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]

1

#

The header provides partial specializations of function_ref for 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:// [func.wrap.ref.ctor], constructors and assignment operatorstemplate function_ref(F*) noexcept; template constexpr function_ref(F&&) noexcept; template constexpr function_ref(nontype_t) noexcept; template<auto f, class U> constexpr function_ref(nontype_t, U&&) noexcept; template<auto f, class T> constexpr function_ref(nontype_t, cv T*) noexcept; constexpr function_ref(const function_ref&) noexcept = default; constexpr function_ref& operator=(const function_ref&) noexcept = default; template function_ref& operator=(T) = delete; // [func.wrap.ref.inv], invocation R operator()(ArgTypes...) const noexcept(noex); private:template<class... T>static constexpr bool is-invocable-using = see below; // exposition only R (thunk-ptr)(BoundEntityType, Args&&...) noexcept(noex); // *exposition only*BoundEntityType* bound-entity; // exposition only}; // [func.wrap.ref.deduct], deduction guidestemplate function_ref(F*) -> function_ref; template function_ref(nontype_t) -> function_ref<see below>; template<auto f, class T> function_ref(nontype_t, T&&) -> function_ref<see below>;}

1

#

An object of classfunction_ref<R(Args...) cv noexcept(noex)> stores a pointer to function thunk-ptr and an object bound-entity.

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).

2

#

Each specialization of function_ref is a trivially copyable type ([basic.types.general]) that models copyable.

3

#

Within [func.wrap.ref],call-args is an argument pack with elements such thatdecltype((call-args))... denoteArgs&&... 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;

1

#

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;

2

#

Constraints:

is_function_v is true, and

is-invocable-using is true.

3

#

Preconditions: f is not a null pointer.

4

#

Effects: Initializesbound-entity with f, andthunk-ptr with the address of a function thunk such thatthunk(bound-entity, call-args...) is expression-equivalent ([defns.expression.equivalent]) toinvoke_r(f, call-args...).

🔗

template<class F> constexpr function_ref(F&& f) noexcept;

5

#

Let T be remove_reference_t.

6

#

Constraints:

remove_cvref_t is not the same type as function_ref,

is_member_pointer_v is false, and

is-invocable-using<cv T&> is true.

7

#

Effects: Initializesbound-entity with addressof(f), andthunk-ptr with the address of a function thunk such thatthunk(bound-entity, call-args...) is expression-equivalent ([defns.expression.equivalent]) toinvoke_r(static_cast<cv T&>(f), call-args...).

🔗

template<auto f> constexpr function_ref(nontype_t<f>) noexcept;

8

#

Let F be decltype(f).

9

#

Constraints: is-invocable-using is true.

10

#

Mandates: If is_pointer_v || is_member_pointer_v is true, then f != nullptr is true.

11

#

Effects: Initializesbound-entity with a pointer to an unspecified object or null pointer value, andthunk-ptr with the address of a function thunk such thatthunk(bound-entity, call-args...) is expression-equivalent ([defns.expression.equivalent]) toinvoke_r(f, call-args...).

🔗

template<auto f, class U> constexpr function_ref(nontype_t<f>, U&& obj) noexcept;

12

#

Let T be remove_reference_t andF be decltype(f).

13

#

Constraints:

is_rvalue_reference_v<U&&> is false, and

is-invocable-using<F, cv T&> is true.

14

#

Mandates: If is_pointer_v || is_member_pointer_v is true, then f != nullptr is true.

15

#

Effects: Initializesbound-entity with addressof(obj), andthunk-ptr with the address of a function thunk such thatthunk(bound-entity, call-args...) is expression-equivalent ([defns.expression.equivalent]) toinvoke_r(f, static_cast<cv T&>(obj), call-args...).

🔗

template<auto f, class T> constexpr function_ref(nontype_t<f>, cv T* obj) noexcept;

16

#

Let F be decltype(f).

17

#

Constraints: is-invocable-using<F, cv T*> is true.

18

#

Mandates: If is_pointer_v || is_member_pointer_v is true, then f != nullptr is true.

19

#

Preconditions: If is_member_pointer_v is true,obj is not a null pointer.

20

#

Effects: Initializesbound-entity with obj, andthunk-ptr with the address of a function thunk such thatthunk(bound-entity, call-args...) is expression-equivalent ([defns.expression.equivalent]) toinvoke_r(f, obj, call-args...).

🔗

template<class T> function_ref& operator=(T) = delete;

21

#

Constraints:

T is not the same type as function_ref,

is_pointer_v 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);

1

#

Effects: Equivalent to:return thunk-ptr(bound-entity, std::forward(args)...);

22.10.17.6.5 Deduction guides [func.wrap.ref.deduct]

🔗

template<class F> function_ref(F*) -> function_ref<F>;

1

#

Constraints: is_function_v is true.

🔗

template<auto f> function_ref(nontype_t<f>) -> function_ref<see below>;

2

#

Let F be remove_pointer_t<decltype(f)>.

3

#

Constraints: is_function_v is true.

4

#

Remarks: The deduced type is function_ref.

🔗

template<auto f, class T> function_ref(nontype_t<f>, T&&) -> function_ref<see below>;

5

#

Let F be decltype(f).

6

#

Constraints:

F is of the formR(G::*)(A...) cv &opt 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.

7

#

Remarks: The deduced type is function_ref<R(A...) noexcept(E)>.