Boost logo

Boost :

From: Joel FALCOU (joel.falcou_at_[hidden])
Date: 2008-06-06 16:21:55


Andrew James a écrit :
> I myself have also implemented a class that has these features within a "traited" framework (explanation to follow). The challenge I have seen, that I'm not clear if it is expressed here, is what if the type whose name you want to dump is also dependent on some template parameter that a frameword user is in charge of?
[...]
> These things being said, I realize this is specific to my framework but it illustrates some issues a boost supported solution could provide.
> We should be able to debug types like std::vector< SomeTypeTheDebugLibraryIsCluelessAbout > w/o requiring the user do a similar amount of work to writing the facility him/herself.

I'm not sure if I understood the problem but currently my identify<>
class can take care of user defined type or user_defined tempalte by
using a simple register macro. I also have a on going list of
pre-registered type for STD and parts of BOOST.

Here is a small example :

#include <boost/identify/identify.hpp>
#include <boost/identify/support/std.hpp>

// Some user template classes
template<class A1,class A2,class A3,class A4,size_t A5> struct foo {};
template<class A1,class A2> struct chu{};

// some class
struct coin {};

BOOST_IDENTIFY_REGISTER_TYPE_ID(coin)
BOOST_IDENTIFY_REGISTER_CUSTOM_TEMPLATE_TYPE_ID(
(class)(class)(class)(class)(size_t), foo)
BOOST_IDENTIFY_REGISTER_TEMPLATE_TYPE_ID(chu,2)

template<class T> struct Test
{
   static inline void Do()
   {
     cout << boost::identify<T>::Name() << endl;
   }
};

int main()
{
   Test<char>::Do();
   Test<coin>::Do();
   Test<chu<float,coin> >::Do();
   Test< std::vector< chu<void,void*>& > >::Do();
   Test<foo<float,long*,volatile double,coin,3> >::Do();
}

The results are :

char
coin
chu<float, coin>
std::vector< chu<void,void*>&
foo< float, signed long*, volatile double, coin, 3 >

the identify.hpp grants the main identify class ans supports for basic
types (POD, pointer, reference, cv qualified types, function types,
function pointers and array mostly) while the support/std.hpp provides
pre-registered identify overload for STD types.

The macro BOOST_IDENTIFY_REGISTER_TYPE_ID declares a new user types to
be displayed. BOOST_IDENTIFY_REGISTER_TEMPLATE_TYPE_ID does the same for
template class with less than 5 tempalte parameters which are all of
tpye class. BOOST_IDENTIFY_REGISTER_CUSTOM_TEMPLATE_TYPE_ID allows
registering tempalte class with more than 5 parameters and with
integralk parameters by specifying a BOOST_PP_SEQ of the arguments.
The burden is no greater for me than registering a type for BOOST_TYPEOF
and is fairly acceptable.

Not sure if other cases are needed. My main concern is being able to
display non-instanciated template class, eg:

identify<std::vector>::Name() displaying std::vector

but this may need another class (like incomplete_identify<> maybe).

-- 
Joel FALCOU
Research Engineer @ Institut d'Electronique Fondamentale
Université PARIS SUD XI
France

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk