Boost logo

Boost :

From: Tobias Schwinger (tschwinger_at_[hidden])
Date: 2007-06-15 16:55:46

Peter Dimov wrote:
> Eric Niebler wrote:
>> Tobias Schwinger wrote:
>>> Tobias Schwinger wrote:
>>>> // [...] tricky nullary case with default ctor detection
>>>> // omitted for simplicity
>>> Doh! It's not possible to detect default constructibility, correct?
>>> So we'd have to declare it as
>>> template<typename T, typename DefaultConstructible =
>>> mpl::false_> struct constructor;
>> No. If the interface is "construct<T>(sequence)", then you can
>> dispatch on the size of the sequence. You'd only try to default
>> construct when you pass an empty sequence.
> Why is there a need to detect a default constructor?

(I probably snipped away too much context...)

A generic function object that constructs an arbitrary type would have
to know (unless having variadic templates, or being able to define
operator() as a nonmember function template).

This generalization would be useful to e.g. say

     boost::bind( constructor<T>(), 55, _2, _1)

or make the implementation of the discussed Fusion utility
'construct<T>(fusion_sequence)' as simple as

     template<typename T, typename FusionSequence>
     T construct<T>(FusionSequence & seq)
         return invoke_function_object(
             constructor<T>(), seq);

(the other stuff exists already).


Boost list run by bdawes at, gregod at, cpdaniel at, john at