Boost logo

Boost :

Subject: Re: [boost] [intro] Preview: Introspection library
From: Stefan Strasser (strasser_at_[hidden])
Date: 2010-06-28 11:13:29

Zitat von Sohail Somani <sohail_at_[hidden]>:

> On 10-06-28 8:00 AM, Stefan Strasser wrote:
>> template<class Mapping>
>> friend void introspect(Mapping mapping,type<A>){
>> mapping
>> (base_class<A_base>() )
>> (member<A,int ,&A::m_a>() )
>> (member<A,float ,&A::m_b>() )
>> (member<A,std::vector<int>,&A::m_vec>())
>> ();
>> }
> I think a library like this would be useful.
> Isn't it simpler to specialize a template? Why does this need to be
> done at run-time?

I assume you mean as opposed to something like

typedef mpl::vector<member<...>,member<...> > introspect;

there are several reasons for this:
  - I prefer the syntax above
  - although it is a runtime function it isn't really executed at
runtime. an optimizing compiler generates no code.
  - if you need a MPL sequence, you can easily obtain one:

struct functor{
   template<class Sequence>
   void operator()(Sequence) const{


  - you can associate state with a member. for example:


which is useful e.g. for algorithms serializing to XML, or mapping a
member to an SQL database field.

  - most algorithms only need to iterate members and don't need a MPL
sequence, which saves lots of instantiations. they simply implement a
functor that gets called for each member and call


> How do you introspect a type's constructors?

none of the algorithms need reflection of constructors or other member
if you need it it can be added without changing the library. it would
probably look something like:

template<class A0,class A1...>
struct constructor{};


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