title: C++11 static_assert: Parameterized error messages
body: <p>In <a href="https://stackoverflow.com/questions/11048827/c11-static-assert-and-functions-to-be-used-therein/11048875#11048875">my previous question</a> I wanted to use static_assert to restrict a template parameter to be a specific subtype. The question was answered, the code for archieving that is as follows:</p>
  
  <pre><code>template &lt;typename T&gt; 
  struct X { 
      static_assert(std::is_base_of&lt;Y,T&gt;::value,"T must be derived from Y!");
  };
  </code></pre>
  
  <p>Now, I want to make the error message more concise. I.e., I want to state which type is violating this constraint. E.g., if class <code>A</code> is not derived from <code>Y</code> and someone instanciates <code>X&lt;A&gt;</code>, then the error message should print "The type parameter must be derived from Y, but <strong>A</strong> isn't".</p>
  
  <p>Is this somehow achievable with the standard library?</p>
  
  <p>I see two challenges:</p>
  
  <ul>
  <li>Assembling strings at compiletime without using boost::mpl</li>
  <li>retrieving the name of the type with which T was instanciated. The name should be meaningful, ideally the same as used in the violating definition. I tried typeid(T).name() but it only returns the mangled name which is not acceptable. I remember that there was some kind of macro that returns the name of something, but I cannot recall that anymore.</li>
  </ul>