What is the stance on partial initializers when declaring

Jacob Carlborg doob at me.com
Fri Jul 22 00:03:53 PDT 2011


On 2011-07-22 03:29, Simen Kjaeraas wrote:
> On Fri, 22 Jul 2011 02:50:52 +0200, bearophile
> <bearophileHUGS at lycos.com> wrote:
>
>> Simen Kjaeraas:
>>
>>> int n;
>>> string s;
>>>
>>> unpack!(n,s) = tuple(4, "O HAI");
>>
>> See my other answer. Beside being long and ugly, it doesn't define the
>> types too. And you can't use it in foreach.
>
> Yeah, I can absolutely see that there are places where this could not
> reasonably be used. Initializing const and immutable data definitely is
> one. And being able to use it in a foreach would be very nice.
>
> Something that might take us part of the way, at least, would be for
> alias this to support typetuples. Thus:
>
> struct Tuple(T...) {
> T fields;
> alias fields this;
> }
>
> void foo(int n, string s) {}
>
> foo(tuple(3, "bar"));
>
> would work. Foreach would direcly benefit from this:
>
> foreach (x, y; zip([1,2,3], "abc")) {} // Look ma! No bananas!

That would be really nice.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list