Boost logo

Boost :

From: Jaakko Jarvi (jajarvi_at_[hidden])
Date: 2002-10-30 15:37:41


> 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 );

If you can control your SpecialObjects, give them a constructor taking
a tuple. Now you can do:

template<class T, class ATuple>
void create_and_run(const ATuple& t)
{
  T anObject(t); return anObject.run();
}

obviously your call will then look like:

create_and_run<SpecialObject>(boost::make_tuple(x, y));

/Jaakko


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