title: How to demangle std::string as std::string
body: <p>I have been using some demangling code already for while to help with some debugging without having to write thousands of lines with dynamic casts or having to implement virtual functions which return the class name.</p>
  
  <pre><code>template &lt;class CLASS&gt;
  std::string getClassName(CLASS &amp;theObject)
  {
      int status = 0;
  
      // Convert real name to readable string
      char *realName = abi::__cxa_demangle(typeid(theObject).name(), nullptr,
                                           nullptr, &amp;status);
      ASSERT(status == 0); // Assert for success
      VERIFY(realName, return std::string());
      // Return as string + prevent memory leaks!
      const std::string result(realName);
      free(realName);
      return result;
  }
  </code></pre>
  
  <p>The idea behind this code is simple, to output the class we are actually using.
  Though after switching to Ubuntu 14.04 I was no longer able to compile using clang and the c++-11/c++-14 standard, so I've switched to using the libc++ instead of libstdc++.</p>
  
  <p>After switching to libc++, I've noticed that when I demangle 'std::string' it no longer outputs 'std::string', though instead it outputs:</p>
  
  <pre><code>std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;
  </code></pre>
  
  <p>Off course this is correct, since std::string is a typedef for std::basic_string.
  Though as far as I can see in both libc++ as libstdc++ this defined the same way, using the typedef. So I don't really understand why this demangling has changed by switching to the libc++.</p>
  
  <p>Has someone an idea why this is different and how to get 'std::string' if CLASS would be 'std::string', and 'myTemplate' when CLASS would be 'myTemplate'?</p>
  
  <p>Tnx in advance!</p>
  
  <p>JVApen</p>