c++ - 可以在 C++11 中模拟 std::is_invocable 吗?
问题描述
我想使用 std::is_invocable,但是我们使用的是 c++11 标准,而 is_invocable 仅适用于 c++17。
有什么方法可以模拟使用 c++11 的功能吗?
谢谢
解决方案
你可以试试这个实现:) 取自 boost C++ 库。我已经使用带有标准 C++14 的 VS2017 对其进行了测试。
template <typename F, typename... Args>
struct is_invocable :
std::is_constructible<
std::function<void(Args ...)>,
std::reference_wrapper<typename std::remove_reference<F>::type>
>
{
};
template <typename R, typename F, typename... Args>
struct is_invocable_r :
std::is_constructible<
std::function<R(Args ...)>,
std::reference_wrapper<typename std::remove_reference<F>::type>
>
{
};
推荐阅读
- c - 检查字符串是否为c中的数字时出现问题
- sql - 如何从一个表中选择一个值,其中在另一个表中满足两个单独的条件对
- javascript - mongodb中的查询过滤器,获取嵌套数组的数据,以及基于嵌套数组的分页
- php - PHP Logic 在 POST 达到 1000 个赞时获得奖励
- javascript - FadeIn 新的背景图像 Jquery
- python-3.x - 根据上一行将列值增加 1
- php - 与 Silverstripe Fluent 的 many_many 关系存在问题
- logstash - Logstash 7 未向索引名称添加日期戳
- c# - 为什么我的登录一直失败使用流畅的等待,尝试显式但没有奏效?
- python - Pandas Correlation - 在两列上处理 0