【问题标题】:Can std::is_invocable be emulated within C++11?可以在 C++11 中模拟 std::is_invocable 吗?
【发布时间】:2018-07-05 09:36:04
【问题描述】:

我想使用 std::is_invocable,但是我们使用的是 c++11 标准,而 is_invocable 仅适用于 c++17。

有什么方法可以模拟使用 c++11 的功能吗?

谢谢

【问题讨论】:

标签: c++ c++11 c++17


【解决方案1】:

你可以试试这个实现:) 取自 boost C++ 库。我已经用 VS2017 和标准 C++14 对其进行了测试。

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>
    >
{
};

【讨论】:

猜你喜欢
  • 2017-10-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-12
  • 2013-10-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多