
On Sat, 02 Jul 2011 01:07:04 +0200, Mathias Gaunard wrote:
On 07/02/2011 12:44 AM, Paul Mensonides wrote:
(I do believe, however, that std::initializer_list<T> is a misfeature. I personally think the { a, b, c } should have been mapped onto a constructor call taking a, b, and c--which may or may not use variadic templates).
Both are possible in C++0x. That's how you initialize tuples.
The { a, b, c } syntax does not map onto constructors. It maps onto std::initializer_list<T> for some particular (and unique) T. With C++0x, T x { U(), U(), U() }; // or whatever the exact syntax is maps onto a constructor T(std::initializer_list<U>). (I haven't played around with the details enough to remember off hand the exact semantics, so bear that in mind.) However, T x { U(), V(), W() }; typically maps onto epic fail. IMHO, std::initializer_list<T> should not exist as a language level type. Variadic templates are enough provided the language maps the above syntax directly to a constructor invocation. E.g. T x { a, b, c } mapping to T(a, b, c). With that, you could have done everything that std::initializer_list<T> could do and much more. (E.g. initialize a tuple containing values of differing types.) You could even have added tools at the library level to make it easier to write the constructors for non-expert users. Given that, C's designated initializers (et al) could have been added to C ++ as a special case of keyword arguments which, in turn, could have been extended to regular functions, not just constructors. Regards, Paul Mensonides