Tuple literal syntax

Tomek Sowiński just at ask.me
Thu Oct 7 14:46:55 PDT 2010


Simen kjaeraas napisał:

> retard <re at tard.com.invalid> wrote:
>> I guess the other places of confusion
>> are interaction with built-in statements and other features, e.g.
>>
>> auto foo = (1,2,3);
>>
>> auto bar = [foo];
>>
>> Should there be some way to construct a [1,2,3] array from the tuple or
>> should the only be a way to construct arrays of the type tuple!(int)[] or
>> something similar.
> 
> The obvious way to do this:
> 
> CommonType!T buildArray( T... )( T arg ) {
>      return [ arg ];
> }
> 
> auto foo = tuple( 1, 2, 3 );
> 
> auto bar = buildArray( foo.expand );

>From a different angle:

auto range = byFields(tuple(1,2,3));

It should take structs, classes, maybe unions. Of course, front() = 5 should update the 
source tuple. Feed it to std.(algorithm|range) for the win!

Also, I'd like to see two flavors:

byFields!(UnificationStrategy.CommonType)(...);  // default
byFields!(UnificationStrategy.Variant)(...);  // wrappers

-- 
Tomek


More information about the Digitalmars-d mailing list