可以在C ++ 11中模拟std :: is_invocable吗? [英] Can std::is_invocable be emulated within C++11?

查看:153
本文介绍了可以在C ++ 11中模拟std :: is_invocable吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'd like to use std::is_invocable, however we are using c++11 standard, while is_invocable is available only from c++17.

可以使用c ++ 11来模拟功能吗?

Is there any way to emulate the functionality using c++11?

谢谢

推荐答案

您可以尝试此实现:)选自boost C ++库。我已经在VS2017和标准C ++ 14上进行过测试。

You can try this implementation:) Taken from boost C++ libraries. I've tested it with VS2017 with standard 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>
    >
{
};

这篇关于可以在C ++ 11中模拟std :: is_invocable吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆