[prev in list] [next in list] [prev in thread] [next in thread] 

List:       boost-users
Subject:    [Boost-users] mpl related question
From:       Istvan Buki <istvan.buki () skynet ! be>
Date:       2004-07-24 12:48:18
Message-ID: 200407241448.18298.istvan.buki () skynet ! be
[Download RAW message or body]

Hello mpl experts,

I'm trying to initialize the elements of an array using rules defined in a 
list of structures. The code below illustrate what I'm trying to achieve. 

The problem I have with this code is that the First_Descriptor structure 
contain this index member that will be used to access the right item of the 
array. This is not nice because it force the writer of this structure to deal 
with implementation details. Is there a way to get rid of this index typedef 
in the *_Descriptor structures by using another construct from the mpl that 
would generate it ?

// The array I need to initialize.
Array_Item array[2];

struct Initializer
{
  template < typename U > void operator()( mpl::identity< U > )
  {
    // This is where array elements are initialized.
    // Note how the index member is used.
    array[U::index::type::value].some_method( U::a_param ) ;
  }
 } ;

// This is one structure containing rules used to initialize array items.
struct First_Descriptor
{
  enum { a_param = 123456 } ;
  typedef mpl::int_< 0 > index ;
}  ;

struct Second_Descriptor
{
  enum { a_param = 2567 } ;
  typedef mpl::int_< 1 > index ;
} ;

// The list of structures containg rules to be applied during array
// initialization.
typedef mpl::list< First_Descriptor, Second_Descriptor > Descriptors ;

// traverse the list and apply the rules.
 mpl::for_each< Descriptors, mpl::make_identity<_> >( Initializer( ) ) ;


Thanks for any help you could provide.

Istvan

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic