Print template typename at compile time

To get a useful compile time name:

Supposing you have some unknown type named ‘T’. You can get the compiler to print it’s type by using it horribly. For example:

typedef typename T::something_made_up X;

The error message will be like:

error: no type named 'something_made_up' in 'Wt::Dbo::ptr<trader::model::Candle>'

The bit after ‘in’ shows the type. (Only tested with clang).

Other ways of triggering it:

bool x = T::nothing;   // error: no member named 'nothing' in 'Wt::Dbo::ptr<trader::model::Candle>'
using X = typename T::nothing;  // error: no type named 'nothing' in 'Wt::Dbo::ptr<trader::model::Candle>'

With C++11, you may already have an object and use ‘decltype’ to get its type, so you can also run:

auto obj = creatSomeObject();
bool x = decltype(obj)::nothing; // (Where nothing is not a real member). 

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)