问题描述
这个问题对于 C++ Get name of type in template 来说是部分常见的。
我正在尝试提出一个扩展为 static_assert(std::is_trivially_destructible<T>::value,#T" is not trivally destructible");
的模板/宏,以便我可以在我的代码中使用速记。但看起来没有编译时方式知道模板中 T 的名称。
使用宏的另一种方法也不好,因为它会将错误移动到不正确的行号(即在宏内)。请参阅下面的宏错误示例:
macro.cpp:5:17: error: static assertion failed: std::vector<int> should be trivial
static_assert(std::is_trivially_destructible<T>::value,#T" should be trivial");
^~~
macro.cpp:10:3: note: in expansion of macro ‘STATIC_ASSERT_TRIVIALLY_DESTRUCTIBLE’
STATIC_ASSERT_TRIVIALLY_DESTRUCTIBLE(std::vector<int>);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)