Reputation: 16148
This is a follow up questions from How to convert typename T to string in c++
I am asking because I would really like to generate nice error messages like
static_assert(one_of<T,Components...>::value,
"Unable to access T because you didn't
use it in filter<Components...>.");
Would print
Unable to access Foo because you did not use it in filter<Bar,Baz,Bat>.
Is something like this now possible in C++11 / 14?
Upvotes: 2
Views: 107
Reputation: 16777
Quoting from the poor(lazy?) man's version of the C++ Standard,
Since message(the second argument to static_assert) has to be a string literal, it cannot contain dynamic information or even a constant expression that is not a string literal itself. Typically, it cannot contain the name of the template type argument.
So, there isn't a way of getting the friendly static_assert
error messages you desire.
Upvotes: 1