Boost logo

Boost :

From: Andrew James (aj_at_[hidden])
Date: 2008-06-06 13:52:06


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?

// potential forward declaration to be specialized
template < typename SomeType_ > struct TypeName;

template < typename Traits_ >
void DoSomething( const TraitedClass< Traits_ >& t ) {
    std::coit << TypeName< TraitedClass< Traits_ > >::Name() << "\n";
}

//Doesn't seem to me the following works and I want this so
// I can have some general name that reflects a traited class
// with no full specialization. This is expressing the fact that
// I can not apriori tell what all future traits will be
template < typename Traits_ >
struct TypeName< typename TraitedClass< Traits_ > > {
};

So, what I really have to do is

template < typename Traits_, typename T_ > struct TypeName;

template < typename Traits_ >
void DoSomething( const TraitedClass< Traits_ >& t ) {
    std::cout << TypeName< Traits_, TraitedClass< Traits_ > >::Name() << "\n";
}

template < typename Traits_ >
struct TypeName< Traits_, TraitedClass< Traits > > {
};

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.

--aj

On 6/6/08 10:26 AM, "Matus Chochlik" <chochlik_at_[hidden]> wrote:

Hi,

The mirror library which I happen to be developing ;-) does (among
other stuff) a similar thing.

The library is still in early stages of development, but if you're interested,
the current version can be found both in the sandbox and in the vault.

My implementation has some drawbacks, like the need to do
type/template registering before they can be reflected
so I would definitelly like to look at your implementation.

On Fri, Jun 6, 2008 at 6:15 PM, Joel FALCOU <joel.falcou_at_[hidden]> wrote:
> Hello,
>
> during the past years, I stumbled across various bugs in template
> meta-programms and found useful to have a small tools that is able to
> display at runtime the exact type of a given object or template type as
> a basic std::string in code fragments like :
>
> template<class T, template<class,class> class X > struct
> {
> static inline DoSomething( T const & x)
> {
> // soem code
> std::cout << "Currently instanciating : "
> << identify< X<T,typename T::type> >::Name()
> << std::endl;
> }
> };
>
> Basically this small library replace typeid and its non-standard name()
> method by a meta-programmed class (identify) which is able to handle
> various classic types (being template or not themselves). I was
> wondering if such a library could be of interest and be submitted as a
> possible addition to Boost or if this scope (type name display) was too
> mundane.
>
> If the former, I'll be glad to post some more material and discuss a
> possible rationale.
>
>
> Regards
>
> --
> Joel FALCOU
> Research Engineer @ Institut d'Electronique Fondamentale
> Université PARIS SUD XI
> France
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
>

best regards,

--
________________
::matus_chochlik
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

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