Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/utility/functional/function ref"

From cppreference.com
< cpp‎ | utility‎ | functional
(add c++26 std::function_ref)
 
m
Line 29: Line 29:
 
{{dsc hitem|Member name|Definition}}
 
{{dsc hitem|Member name|Definition}}
 
{{dsc|{{tti|bound-entity}} {{mark|private}}|an object that has an unspecified {{named req|TriviallyCopyable}} type {{tt|BoundEntityType}}, that satisfies {{lconcept|copyable}} and is capable of storing a pointer to object value or pointer to function value<br>{{mark expos mem obj}}}}
 
{{dsc|{{tti|bound-entity}} {{mark|private}}|an object that has an unspecified {{named req|TriviallyCopyable}} type {{tt|BoundEntityType}}, that satisfies {{lconcept|copyable}} and is capable of storing a pointer to object value or pointer to function value<br>{{mark expos mem obj}}}}
{{dsc|{{tti|thunk-ptr}} {{mark|private}}|a pointer to function of type {{c|R(*)(BoundEntityType, Args&&...) noexcept(/*is-noexcept*/)}} where {{c|/*is-noexcept*/}} is {{c/core|true}} if {{c/core|noexcept}} is present in function signature<br>{{mark expos mem obj}}}}
+
{{dsc|{{tti|thunk-ptr}} {{mark|private}}|a pointer to function of type {{c|R(*)(BoundEntityType, Args&&...) noexcept(/*noex*/)}} where {{c|/*noex*/}} is {{c/core|true}} if {{c/core|noexcept}} is present in function signature as part of the template parameter of {{tt|std::function_ref}}<br>{{mark expos mem obj}}}}
 
{{dsc end}}
 
{{dsc end}}
  

Revision as of 03:16, 18 December 2023

 
 
Utilities library
General utilities
Relational operators (deprecated in C++20)
 
Function objects
Function wrappers
(C++11)
function_ref
(C++26)
(C++11)
Function invocation
(C++17)(C++23)
Identity function object
(C++20)
Transparent operator wrappers
(C++14)
(C++14)
(C++14)
(C++14)  
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)

Old binders and adaptors
(until C++17*)
(until C++17*)
(until C++17*)
(until C++17*)  
(until C++17*)
(until C++17*)(until C++17*)(until C++17*)(until C++17*)
(until C++20*)
(until C++20*)
(until C++17*)(until C++17*)
(until C++17*)(until C++17*)

(until C++17*)
(until C++17*)(until C++17*)(until C++17*)(until C++17*)
(until C++20*)
(until C++20*)
 
 
Defined in header <functional>
template< class... >
class function_ref; // not defined
(1) (since C++26)
template< class R, class... Args >

class function_ref<R(Args...)>;
template< class R, class... Args >
class function_ref<R(Args...) noexcept>;
template< class R, class... Args >
class function_ref<R(Args...) const>;
template< class R, class... Args >

class function_ref<R(Args...) const noexcept>;
(2) (since C++26)

Class template std::function_ref is a non-owning function wrapper. std::function_ref objects can store and invoke reference to Callable target - functions, lambda expressions, bind expressions, or other function objects, but not pointers to member functions and pointers to member objects. std::nontype can be used to construct std::function_ref by passing function pointers, pointers to member functions, and pointers to member objects.

std::function_refs supports every possible combination of cv-qualifiers, and noexcept-specifiers not including volatile provided in its template parameter.

Every specialization of std::function_ref is a TriviallyCopyable type that satisfies copyable.

Contents

Member objects

Member name Definition
bound-entity (private) an object that has an unspecified TriviallyCopyable type BoundEntityType, that satisfies copyable and is capable of storing a pointer to object value or pointer to function value
(exposition-only member object*)
thunk-ptr (private) a pointer to function of type R(*)(BoundEntityType, Args&&...) noexcept(/*noex*/) where /*noex*/ is true if noexcept is present in function signature as part of the template parameter of std::function_ref
(exposition-only member object*)

Member functions

constructs a new function_ref object
(public member function) [edit]
assigns a function_ref
(public member function) [edit]
invokes the stored thunk of a function_ref
(public member function) [edit]

Deduction guides

Notes

Feature-test macro Value Std Feature
__cpp_lib_function_ref 202306L (C++26) std::function_ref

Example

See also

(C++11)
copyable wrapper of any copy constructible callable object
(class template) [edit]
copyable wrapper of any copy constructible callable object that supports qualifiers in a given call signature
(class template) [edit]
move-only wrapper of any callable object that supports qualifiers in a given call signature
(class template) [edit]
value construction tag
(tag)[edit]