c++ - Strange construct that used as tag in boost::spirit::x3 -
what strange language construct x< class y > y;
in following context?
#include <iostream> #include <sstream> #include <typeinfo> #include <type_traits> #include <cstdlib> #include <cxxabi.h> template< typename t > std::string const type_info_str() { int status = 0; auto realname_(abi::__cxa_demangle(typeid(t).name(), nullptr, nullptr, &status)); switch (status) { case -1: return "could not allocate memory"; case -2: return "invalid name under c++ abi mangling rules"; case -3: return "invalid argument demangle"; } std::ostringstream oss; if (std::is_volatile< t >::value) { oss << "volatile "; } oss << realname_; std::free(realname_); if (std::is_const< t >::value) { oss << " const"; } if (std::is_rvalue_reference< t >::value) { oss << " &&"; } else if (std::is_lvalue_reference< t >::value) { oss << " &"; } return oss.str(); } template< typename t > struct x { }; int main() { x< class y > y; std::cout << type_info_str< decltype(y) >() << std::endl; // x<main::y> return exit_success; }
what purpose , semantics?
let's break down:
x <class y> y | ^^^^^^^^^ | | | | | | | | | ---> name of variable | | | ---> struct template instantiated type | (in case, type incomplete class named y) | ---> struct declared globally
as agent_l mentioned, there no conflict between class name , variable because it can inferred context meant: type or variable.
Comments
Post a Comment