首页 > 解决方案 > 如何检查模板参数化回调函数签名是一种

问题描述

在一个流程中,我设置了一个模板化回调函数,如下所示:

otherobju_ptr->Req(std::bind(&A::test<uint16_t>,this,std::placeholders::_1), id);

现在在调用回调之前,我需要验证回调是否是有效的签名类型:

class otherobj  
{
public:
    using CallbackType = std::function<void(const bool&)>;
    int Reg( CallbackType callback, uint32_t& id)
    {
         //Need to check if the function template parameter is correct
          // Trying the below way but not sure where we can give the template parameter <bool>
           static_assert(std::is_convertible_v<decltype(callback), std::function<void(const bool&)>>, "Wrong Callback function");
    }
};  

我无法找到解决方案,因为签名如下:

 static_assert(std::is_convertible_v<decltype(callback), std::function<void<bool>(const bool&)>>, "Wrong Signature!"); 

它出错了 - 有没有一种方法可以验证 std::function 回调的模板参数类型?

标签: c++c++11

解决方案


推荐阅读