Namespaces
Variants

std:: function_ref

From cppreference.net
Utilities library
Function objects
Function invocation
(C++17) (C++23)
Identity function object
(C++20)
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++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* )
定义于头文件 <functional>
template < class ... >
class function_ref ; // 未定义
(1) (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) (C++26 起)

类模板 std::function_ref 是一种非拥有型函数包装器。 std::function_ref 对象能够存储并调用对 可调用对象 目标 的引用——包括函数、 lambda 表达式 绑定表达式 或其他函数对象,但不包括指向成员函数的指针和指向成员对象的指针。 std:: nontype 可用于通过传递函数指针、指向成员函数的指针和指向成员对象的指针来构造 std::function_ref

std::function_ref 支持其模板参数中提供的所有可能的 cv限定符 (不包括 volatile )与 noexcept说明符 的组合。

每个 std::function_ref 的特化都是一个满足 copyable 可平凡复制 类型。

目录

成员类型

成员 定义
BoundEntityType (私有) 未指定的 TriviallyCopyable 类型,满足 copyable 概念,且能够存储对象指针值或函数指针值
( 仅用于说明的成员类型* )
FunctionPointerType (私有) R ( * ) ( BoundEntityType  , Args && ... ) noexcept ( noex  )

其中 noex true (当函数签名中作为 std::function_ref 模板参数的一部分包含 noexcept 时),否则为 false
( 仅用于说明的成员类型* )

数据成员

成员 定义
BoundEntityType bound-entity 绑定实体对象
( 仅用于说明的成员对象* )
FunctionPointerType thunk-ptr 存储的函数指针
( 仅用于说明的成员对象* )

成员函数

构造新的 function_ref 对象
(公开成员函数)
赋值 function_ref
(公开成员函数)
调用 function_ref 存储的 thunk
(公开成员函数)

推导指引

注释

功能测试 标准 功能
__cpp_lib_function_ref 202306L (C++26) std::function_ref

示例

参见

(C++11)
任何可复制构造可调用对象的可复制包装器
(类模板)
支持给定调用签名中限定符的任何可复制构造可调用对象的可复制包装器
(类模板)
支持给定调用签名中限定符的任何可调用对象的仅移动包装器
(类模板)
值构造标签
(标签)