将字符串文字添加到 static_assert
有没有办法结合 static_assert 的输出?我的意思是这样的:
template<class T>
struct X
{
static_assert(std::is_signed<T>::value, "Type " + T + " must be signed.");//this doesn't work
};
Is there a way to combine what's going to be output by static_assert? What I mean is this:
template<class T>
struct X
{
static_assert(std::is_signed<T>::value, "Type " + T + " must be signed.");//this doesn't work
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基于这不能编译
或这
两者都出现错误
错误:预期字符串文字
,那么我不得不得出结论,这是不可能的。“字符串文字由源字符集中的零个或多个字符组成,并用双引号 (") 括起来。字符串文字表示一系列字符,这些字符组合在一起形成一个以 null 结尾的字符串。” - C++ 字符串文字
您可能需要考虑使用
Boost::StaticAssert
因为这可能会给你你正在寻找的东西。On the basis that this does not compile
nor this
Both with errors
error: expected a string literal
then I would have to conclude that it is not possible."A string literal consists of zero or more characters from the source character set surrounded by double quotation marks ("). A string literal represents a sequence of characters that, taken together, form a null-terminated string." - C++ String Literals
You might want to consider using
Boost::StaticAssert
as this might give you what you are looking for.