Namespaces
Variants

std::experimental::ranges:: invoke

From cppreference.net
template < class F, class ... Args >
std:: result_of_t < F && ( Args && ... ) > invoke ( F && f, Args && ... args ) ;
(ranges TS)

调用 Callable 对象 f 并传入参数 args ,返回结果,如同执行 return INVOKE ( std:: forward < F > ( f ) , std:: forward < Args > ( args ) ... ) ; ,其中 INVOKE(f, t1, t2, ..., tN) 定义如下:

  • std:: is_base_of < T, std:: decay_t < decltype ( t1 ) >> :: value true ,则 INVOKE ( f, t1, t2, ..., tN ) 等价于 ( t1. * f ) ( t2, ..., tN )
  • 否则 INVOKE ( f, t1, t2, ..., tN ) 等价于 ( ( * t1 ) . * f ) ( t2, ..., tN )
  • std:: is_base_of < T, std:: decay_t < decltype ( t1 ) >> :: value true ,则 INVOKE ( f, t1 ) 等价于 t1. * f
  • 否则 INVOKE ( f, t1 ) 等价于 ( * t1 ) . * f
  • 否则, INVOKE ( f, t1, t2, ..., tN ) 等价于 f ( t1, t2, ..., tN ) (即 f 是一个 FunctionObject )。

参数

f - 将被调用的 Callable 对象
args - 传递给 f 的参数

参见

(C++17) (C++23)
以给定参数调用任意 Callable 对象 并可指定返回类型 (C++23 起)
(函数模板)