Boost logo

Boost :

From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2003-10-07 19:28:51

<cppljevans_at_[hidden]> escribió en el mensaje news:blv88c$pl5$
> On 10/07/2003 03:05 PM, Fernando Cacciola wrote:
> > cppljevans_at_[hidden] wrote:
> [snip]
> >>>Any ideas how to enable an arbitrary number and types of args to
> >>>new_policied CTOR?
> >>>
> >
> >
> > Hi, sorry for the late response, I've been busy as usual.
> No problem :)
> > I don't think I undestand your problem.
> >
> > What doesn't work with new_policied.cpp exactly?
> >
> > The code in the attachement alone looks fine to me,
> >
> > so why desn't it work?
> >
> Well, the code as presented works; however, I wanted something
> that would work for an arbitrary number of arguments, just like
> your in_place. For example, suppose:
> struct T0{ T0();}; struct T1{T1(int);}; struct T2{T2(int,int);};
> Now I want the following to work:
> new_policied<T0,S> np0();
> new_policied<T1,S> np1(0);
> new_policied<T2,S> np2(0,0);
> However, the code which I posted requires three arguments.
> Is that not similar to what in_place<T>(...) does? In other words,
> for each CTOR argument signature, S, in T, there is a
> corresponding CTOR argument signature for
> new_policied<T>::new_policied(S); where S can be replaced with
> any arglist for T's CTOR's.
Ok, now I see the problem.

What you need is to reproduce the preprocessor magic that is used to expand the code to a series of CTOR overloads taking an
increasing number of arguments. I can tell you how to do that....

For starters, I guess that for simplicity you can leave the default contrusctor (the 'zero-arguments' overload) explicit and use
the macros to generate the rest of the overloads.

The code I used is a bit more complicated that what you need because I'm generating a series of entire classes while all you
need is a series of CTOR overloads.

Warning: This is untested. Is off the top of my head, but you'll get the idea:


  template< class T, BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n),class A) > \
  new_policied ( BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_INC(n),A,const& a) ) \
    : super_type(new subj_type(Referent(BOOST_PP_ENUM_PARAMS( BOOST_PP_INC(n), a ))))
  {} \

  < typename Referent
  , typename StoragePolicy
class new_policied
  : private std::auto_ptr<boost::compressed_pair<StoragePolicy,Referent> >
    typedef boost::compressed_pair<StoragePolicy,Referent> > subj_type;
    typedef std::auto_ptr<subj_type> super_type;

    new_policied() ....

   // Other overloads



Fernando Cacciola

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