I've seen many posts explaining how to generate a unique id for a class.
In my case, the id is chosen by the user (for various reasons), but I want to make sure that no id is used twice in different classes.
I reduced my problem to the following code :
struct A {}; struct B {};
template <typename T> struct traits {};
template <> struct traits<A> { static constexpr size_t id() { return 0; }}
template <> struct traits<B> { static constexpr size_t id() { return 1; }}
Now, is there an easy way for me to make sure that someone does not add a specialization of the trait with a duplicated id :
struct C {};
template <> struct traits<C> { static constexpr size_t id() { return 1; // this should static_assert ! }}
I can use C++11, and I don't want to abuse the pre-processor.
If possible, the solution should not require anything special from the code specializing the trait (i.e if the check can be done externally by looking at already existing specializations, it would be great).
Thanks