title: compile time check that trait specialization has unique id
body: <p>I've seen many posts explaining how to generate a unique id for a class.</p>
  
  <p>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.</p>
  
  <p>I reduced my problem to the following code :</p>
  
  <pre><code>struct A {}; struct B {};
  
  template &lt;typename T&gt; struct traits {};
  template &lt;&gt; struct traits&lt;A&gt; { static constexpr size_t id() { return 0; }}
  template &lt;&gt; struct traits&lt;B&gt; { static constexpr size_t id() { return 1; }}
  </code></pre>
  
  <p>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 :</p>
  
  <pre><code>struct C {};
  template &lt;&gt; struct traits&lt;C&gt; { static constexpr size_t id() { return 1; // this should static_assert ! }}
  </code></pre>
  
  <p>I can use C++11, and I don't want to abuse the pre-processor.</p>
  
  <p>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).</p>
  
  <p>Thanks</p>