adding string literal to static_assert
Is there a way to combine what's going to be output by static_assert? What I mean开发者_StackOverflow社区 is this:
template<class T>
struct X
{
static_assert(std::is_signed<T>::value, "Type " + T + " must be signed.");//this doesn't work
};
On the basis that this does not compile
int main()
{
const char c[2] = "1";
static_assert(1==1, c)
}
nor this
int main()
{
const char* c = "1";
static_assert(1==1, c)
}
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.
精彩评论