add eoStoreFunctor::pack to allocate & store in one line
Instead of calling `new`, then `state.storeFunctor`, the user can just call `Class& inst = state.pack< Class >( params )` in one line. Use C++11's variadic templates.
This commit is contained in:
parent
38e3f40bad
commit
7e766f848d
1 changed files with 28 additions and 12 deletions
|
|
@ -69,6 +69,22 @@ public:
|
|||
return *r;
|
||||
}
|
||||
|
||||
/** Allocate the given functor, store it and return its reference.
|
||||
*
|
||||
* Indicate the class to instanciate as template paramater,
|
||||
* and pass its constructor arguments.
|
||||
*
|
||||
* @code
|
||||
* eoSelect<EOT>& selector = state.pack< eoRankMuSelect<EOT> >( mu );
|
||||
* @endcode
|
||||
*/
|
||||
template<class Functor, class... Args>
|
||||
Functor& pack( Args&&... args )
|
||||
{
|
||||
Functor* f = new Functor(args...);
|
||||
return this->storeFunctor(f);
|
||||
}
|
||||
|
||||
private :
|
||||
|
||||
/** no copying allowed */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue