[英]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.