Boost logo

Boost :

From: Tobias Schwinger (tschwinger_at_[hidden])
Date: 2007-09-17 15:36:41


Marco Costalba wrote:
> template<typename T1, typename T2> /* two arguments case */
> static Base* object(detail::KeyRef nm, T1 a1, T2 a2) {

<...>

> I want to easy the user from the burden to specifying template
> parameters, so use template parameters deduction.

Template argument deduction doesn't work like this. Gotta say 'T1&'
(this one only allows LValues) or 'T1 const&' (this one also allows
RValues and is always const).

We call it "The Forwarding Problem", see

     http://tinyurl.com/6enrw

for details.

> template<typename Base, typename Values typename FnType>
> struct CreatorClass: public SignatureClass<Base, Values> {
>
> typedef typename FnType::result_type result_type;
>
> CreatorClass(const FnType& fn) : functor(fn) {}
>
> virtual result_type operator()(Values& v) const {
>
> return boost::fusion::invoke_function_object(functor, v);
> }
>
> FnType functor;
> };

Just BTW: virtual operator() almost always indicates that one's better
off using Boost.Function...

> int objCnt = 6;
> Test* t = Factory::object(objCnt);

Of course, because the reference isn't deduced (see above).

> How can I modify the code above to let pack arguments in a vector,
> handling always passing the packed vector by reference and finally
> call invoke_function_object() ?

Try plugging your function object into boost::unfused_generic.

Regards,
Tobias


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