c++ - Demangling and <sstream> results in "ambiguous reference to __gnu_gxx namespace" -
when need print type info @ runtime, apply demangling std::type_info::name()
result. implementation gcc, uses abi::__cxa_demangle()
:
#include <cxxabi.h> gcc demangling implementation std::string demangle( const std::string& name ) { int status; return std::string( abi::__cxa_demangle( name.c_str() , 0 , 0 , &status ) ); return name; }
today writting to_string
template allows me print content of typelist. avoid std::string
concatenations, used string stream, std::ostringstream
:
template<typename t> struct to_string_t { operator std::string() { return demangle( typeid( t ).name() ); } }; template<typename... ts> struct to_string_t<mpl::list<ts...>> { operator std::string() { std::ostringstream os; os << '[' << _to_string<mpl::list<ts...>>() << ']'; return os.str(); } };
_to_string
class template implements operator<<
to print recursively content of typelist stream. (i don't include not bloat post non-related metaprogramming code).
this works without demangling. when include <cxxabi>
implement demangling, compiler shows ambiguous reference __gnu_gxx namespace
error in sstream.h
.
what reason?
Comments
Post a Comment