c++ - 如何检查模板参数化回调函数签名是一种
问题描述
在一个流程中,我设置了一个模板化回调函数,如下所示:
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 回调的模板参数类型?
解决方案
推荐阅读
- ruby-on-rails - 如何在Rails中保存可变数量的相同类型和相同名称的参数?
- flutter - Flutter - 如何在工具栏中对齐徽章图标?
- apache - 主域和子域指向同一个目录
- java - 如何防止或删除后台 Java 进程中的前台文本输入?
- javascript - 无法弄清楚为什么我不断收到 [ERR_HTTP_HEADERS_SENT] 错误
- android - 选择文件后崩溃
- c# - Linq to Entities 从 2 个总和中查询总和
- excel - 在 VBA 中的不同子项中访问字典
- python - 在 python 中的数据帧上应用一种热编码
- expression - 脚本 qlikview 中的策略状态