Re: [boost] [fusion] unpack into constructor?

Eric Niebler wrote:
Tobias Schwinger wrote:
Eric Niebler wrote:
Is the sort of thing you are looking for?
fused_ctor<T> fc; T t = fc(sequence);
Yes, that's the thing.
OK, but why duplicate the unpacking of the Sequence?
All it takes is yet another adapter encapsulating a type's ctor(s) in a function object to just use fusion::(invoke|fused)_function_object. E.g:
<snip>
Client code (at function scope):
invoke_function_object( ctor<my_class>(), argseq );
Yes, that's exactly it. Now, put it in Fusion so I don't have to write a function object with N overloads. :-)
So what is the interface that would be preferred. We can: 1) Provide class ctor<T> as part of the Fusion public interface, and let users call invoke and create fused<ctor<T> > objects. 2) We can provide invoke_ctor<T> and fused_ctor<T>, implement them in terms of a private detail::ctor<T>. This might be a bit more convenient for users, and would give us more scope for optimizing this use case under the hood 3) Provide both Personally I'd probably prefer 2 as its a bit less typing for users, and gives us more implementation leeway, but I'm fine with 1 if others prefer it. I think the ctor shorthand should be spelt construct as well, to make things a bit more friendly. Thanks Dan ___________________________________________________________ Yahoo! Mail is the world's favourite email. Don't settle for less, sign up for your free account today http://uk.rd.yahoo.com/evt=44106/*http://uk.docs.yahoo.com/mail/winter07.htm...

dan marsden wrote:
Eric Niebler wrote:
Tobias Schwinger wrote:
All it takes is yet another adapter encapsulating a type's ctor(s) in a function object to just use fusion::(invoke|fused)_function_object. E.g:
<snip>
Client code (at function scope):
invoke_function_object( ctor<my_class>(), argseq );
Yes, that's exactly it. Now, put it in Fusion so I don't have to write a function object with N overloads. :-)
So what is the interface that would be preferred. We can: 1) Provide class ctor<T> as part of the Fusion public interface, and let users call invoke and create fused<ctor<T> > objects.
I think that this 'ctor'-thingy should be public: It seems not too difficult to find a general use case without argument unpacking, e.g. make boost::bind applicable to constructors. However, Fusion isn't necessarily the best place for it (the stuff in boost/utility or the "Bind utilities", 'mem_fn' and 'ref', are probably better neighbors). Is there such a thing somewhere in Boost already, perhaps?
2) We can provide invoke_ctor<T> and fused_ctor<T>, implement them in terms of a private detail::ctor<T>. This might be a bit more convenient for users, and would give us more scope for optimizing this use case under the hood 3) Provide both
I don't believe there is much to optimize until someone proofs it (as the wrapper should be easy to eliminate compared to the actual unpacking - especially with nested views). Also, I'm not sure that making the library harder to learn and maintain is worth the convenience it buys. There are already too many variants (though with C++0x features things will become much better). Regards, Tobias
participants (2)
-
dan marsden
-
Tobias Schwinger