簡體   English   中英

可以在C ++ 11中模擬std :: is_invocable嗎?

[英]Can std::is_invocable be emulated within C++11?

我想使用std :: is_invocable,但我們使用的是c ++ 11標准,而is_invocable只能從c ++ 17獲得。

有沒有辦法使用c ++ 11模擬功能?

謝謝

你可以試試這個實現:)來自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>
    >
{
};

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM