Boost logo

Boost :

From: Marc Jacobs (marcja_at_[hidden])
Date: 2002-10-30 13:11:04


template< class T >
void create_and_run() { T t; t.run(); }

template< class T, typename A1 >
void create_and_run( A1 a1 ) { T t( a1 ); t.run() }

template< class T, typename A1, typename A2 >
void create_and_run( A1 a1, A2 a2 ) { T t( a1, a2 ); t.run() }

// etc. ad nauseum; try boost preprocessor library to save repetition for N
args

create_and_run< SpecialObject >( x, y );

Marc Jacobs

"Martin Bosticky" <mbosticky_at_[hidden]> wrote in message
news:app36t$dc9$1_at_main.gmane.org...
> Hello boosters
>
> I am passing a whole group of parameters to a function and then i
construct
> an object with exactly the same parameters passed into the constructor.
>
> ie.
> void MyFunction(const int& x, const AClass& y)
> {
> SpecialObject anObject(const int& x, const AClass& y);
>
> return anObject.run();
> }
>
> I am doing this a lot and with different combinations and numbers of
> parameter. I am wondering if there is a clever way to do this so i can
save
> my self some typing. This is a simple example but in practice I could be
> passing say 5 parameters in.
>
> My first attempt was to declare the class within the function and hoping
> that the run() function of the class would have access to the passed
> parameters as if they were globals or something. Unfortunately i could not
> get this to work.
>
> If there was a clever solution then perhaps it could become part of boost
> library.
>
> Any suggestions appreciated, Martin.
>
>
>
>
>
>
> _______________________________________________
> 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