Login or Register

Features Right Core compiler features

__cp_typestringliteral

Intrinsic To Turn Types Into String Literals

This article was updated on 2012-01-12 13:06:38


As of release 2.5 (19th Dec 2011) the Offload™ C++ compiler provides the intrinsic __cp_typestringliteral(type) which returns the string literal of a type. This can be useful for example when debugging templated code, but also to determine the type of variables or typedefs whose declarations do not make it obvious what the actual type is (for example could be declared using another typedef or template).

#include <iostream>

template <class T> void f(T)
{
   printf(\"The type is %s \\n\",__cp_typestringliteral(T));
}

template <class T> struct str {};

int main()
{  
    f(str<int>());
    f([](){return str<double>();});
    printf("std::cout is of type %s\n", __cp_typestringliteral(decltype(std::cout)) );   
}

 The above code prints:

The type is struct str<int >
The type is lambda<mainlambdatest2.cpp(13)>
std::cout is of type class std::basic_ostream<char ,std::char_traits<char > >