title: Detect when multiple enum items map to same value
body: <p>Is there a compile-time way to detect / prevent duplicate values within a C/C++ enumeration? </p>
  
  <p>The catch is that <strong>there are multiple items which are initialized to explicit values</strong>.</p>
  
  <p><strong>Background:</strong></p>
  
  <p>I've inherited some C code such as the following:</p>
  
  <pre><code>#define BASE1_VAL    (5)
  #define BASE2_VAL    (7)
  
  typedef enum
  {
    MsgFoo1A = BASE1_VAL,       // 5
    MsgFoo1B,                   // 6
    MsgFoo1C,                   // 7
    MsgFoo1D,                   // 8
    MsgFoo1E,                   // 9
    MsgFoo2A = BASE2_VAL,       // Uh oh!  7 again...
    MsgFoo2B                    // Uh oh!  8 again...
  } FOO;
  </code></pre>
  
  <p>The problem is that as the code grows &amp; as developers add more messages to the <code>MsgFoo1x</code> group, eventually it overruns <code>BASE2_VAL</code>.</p>
  
  <p>This code will eventually be migrated to C++, so if there is a C++-only solution (template magic?), that's OK -- but a solution that works with C and C++ is better.</p>