Problem
The following does not build because the message is not a string-literal.
template<typename T>
struct Foo
{
Foo()
{
static_assert( is_pod<T>::value, typeid(T).name() );
}
};
Ultimately, I would like a failure message like "Bar must be a pod-type", if I try to compile Foo<Bar> fb;
.
Is it possible to build this string during compile-time, as required by static_assert
?
It's not possible to build the required string at compile time and to put it in the message, but this is usually not a problem in practice as the error message will contain the calling context and you can always create a wrapper for your
static_assert
which shows the type in the error message:yields
Note the
note: ...
where the wrapper with the typestd::string
(or here:std::basic_string<char>
) is shown.Live example (Clang)
For GCC, the error message is also very nice:
Live example (GCC)