Boost logo

Boost :

From: Larry Evans (cppljevans_at_[hidden])
Date: 2006-09-25 14:53:21


On 09/25/2006 01:00 PM, Eric Niebler wrote:
> Generic programming is fairly well understood. Concepts define
> requirements, types model concepts, generic code manipulates models via
> valid expressions for that concept, etc. Also pretty well understood is
> how to define customization points so that arbitrary types can be made
> to model a concept non-intrusively.
>
> But these techniques seem to break down for object construction. Consider:
>
> template< class Inner >
> struct facade
> {
> facade( /* what here? */ )
> : inner_( /* and what here? */ )
> {}
> private:
> Inner inner_;
> };
>
> How does facade know how to initialize inner_? The answer affects how
> facade itself should be initialized.
>
> One possibility is that facade defines N constructors that take up to N
> arguments, and just forwards them to inner_. That might work in this
> narrow case, but what if facade has 2 inner objects of different types?
> How should constructor arguments get dispatched to the different
> sub-objects? In general, facade has no way of knowing. Is this a problem
> others have run into? What sorts of techniques are people using?

AFAICT, This similar to the problem I ran into with the array extension
to Andy Little's fusion matrix. Andy wanted the ability to initialize
with something like:

   maxtrix<...whatever...> a_matrix
     ( a0_0, a0_1, ... , a0_m
     , a1_0, a1_1, ... , a1_m
     ...
     , an_0, an_1, ... , an_m
     )

However, with the array extension
(see <boost-vault>/Template Metaprogramming/array.zip)
I had to have something like that shown here:

http://archives.free.net.ph/message/20060917.155443.96aa800a.en.html

What I needed was something that would emulate the way structs c or
c++ are intialized (with nested {}'s). IOW, instead of requiring all
the typedefs for the rank*_type's, there would be someway to emulate:

   matrix<...whatever...> a_matrix
   { { a0_0, a0_1, ... , a0_m}
   . { a1_0, a1_1, ... , a1_m}
   ...
   , { an_0, an_1, ... , an_m}
   }

My first guess as to how to do it would be to somehow use BOOST_PP
nested sequences passed to some new macro which would reformat it
into something like what was shown in the 96aa800a.en.html post
mentioned above.
>
> I have come up with a little generic object construction utility using
> Boost.Parameter that works for me. It allows you to non-intrusively
> associate named parameters with a type for the purpose of construction,
> and a way to forward a (possibly filtered) argument pack on to
> sub-objects. Is there general interest in such a utility?
>
Yes. I'd like to see how this is done. In particular, I like to
see if it would help with the array problem mentioned above.


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