[英]Determine return type of C++ std algorithm function like count_if
如何像std::count_if一样确定std:: function 的类型? 理想情况下,我想要以下内容
using ret = std::invoke_result_t<std::count_if, const char*, const char*,
std::function<bool(const char)>>;
但由于多种原因,这不起作用。 我可以通过以下方式靠近:
using f = std::function<bool(const char)>;
using ret = std::invoke_result_t<std::count_if, const char*, const char*, f>;
但这仍然不够。
错误:
expected a type, got 'std::count_if'
最简单的方法就是像这样使用 decltype:
using type = decltype(
std::count_if(
std::declval<const char*>(),
std::declval<const char*>(),
std::function<bool(const char)>{}
)
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.