Boost logo

Boost :

Subject: Re: [boost]  Is there interest in typeid(TYPE).name() like function that does not require RTTI
From: Abel Sinkovics (abel_at_[hidden])
Date: 2012-05-30 13:06:35

Hi Antony,

> Hi,
> Would be there some interest in function for getting class name without RTTI?

We've been using similar solutions for unit testing template
metaprograms (Mpllibs.Metamonad, Mpllibs.Metaparse). For example when we
test that evaluating "metafunction_to_test<mpl::int_<13> >::type" gives
"mpl::int_<11>" as the result, the testing code looks like the following:

mpl::equal_to<mpl::int_<11>, metafunction_to_test<mpl::int_<13> >::type>

we give the code to the metaprogramming testing framework in
Mpllibs.Metatest that evaluates it and when it fails, generates code
pretty-printing the above angly-bracket expression. That pretty-printed
expression (and the result of the test) can be given to some unit
testing framework (Metatest's own, Boost.Test, CppUnit, etc.) that
displays it.

Given that the above code enforces the evaluation of
"metafunction_to_test<mpl::int_<13> >" this solution can generate error
reports like:

mpl::equal_to<mpl::int_<11>, mpl::int_<20>>

which can be really helpful for metaprogram development.

Getting class names could help with type pretty-printing, however,
metaprogramming library authors should be able to override it (eg.
pretty-printing an mpl::vector should give something like "vector<int,
char>" instead of the internals of vector's implementation).

We have created a template class (mpllibs::metatest::to_stream) for type
pretty-printing in Mpllibs.Metatest, but it needs further improvements.
It is specialised for a number of types and prints "???" for the rest.
We tried to use RTTI as well but:
- it enforced the evaluation of otherwise unevaluated lazy
metaprogramming expressions
- it didn't give readable output (for metaprograms)

So a way of getting a class name could improve this solution.

All the code I'm talking about is in the following git repository:


Boost list run by bdawes at, gregod at, cpdaniel at, john at