|
Boost : |
From: Tobias Schwinger (tschwinger_at_[hidden])
Date: 2007-06-14 16:20:54
Eric Niebler wrote:
> Hartmut Kaiser wrote:
>>
>> dan marsden wrote:
>>> I don't think we've got anything that supports this directly
>>> at the moment.
As long as we're talking about Fusion/functional - no we haven't.
>>> Is the sort of thing you are looking for?
>>>
>>> fused_ctor<T> fc;
>>> T t = fc(sequence);
>>>
>>> Where fused_ctor::operator()(Seq const&) breaks up the
>>> sequence into args for the T ctor.
>
>
> 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:
// untested code for illustration only
template<typename T>
struct ctor
{
typedef T result_type;
// [...] tricky nullary case with default ctor detection
// omitted for simplicity
template<typename T0>
T operator(T0 & a0) const
{
return T(a0);
}
template<typename T0, typename T1>
T operator(T0 & a0, T1 & a1) const
{
return T(a0,a1);
}
// [...]
// Note:
// Sequence elements are unpacked as lvalues, so const
// qualifiers on the argument types of operator() can be
// deduced
};
Client code (at function scope):
invoke_function_object( ctor<my_class>(), argseq );
Regards,
Tobias
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk