tuple slicing operator

via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Aug 10 02:51:31 PDT 2014


On Saturday, 9 August 2014 at 19:26:46 UTC, Meta wrote:
> On Saturday, 9 August 2014 at 16:39:34 UTC, Vlad Levenfeld 
> wrote:
>> I may be misunderstanding the intended semantics of the [] 
>> operator but I've come to interpret x[] to mean "give me x as 
>> a range" and this is the meaning I intend when I overload it 
>> in my own structs.
>>
>> But -
>>
>> auto z = tuple (1,1,1);
>> pragma (msg, typeof(z)); // Tuple!(int, int, int)
>> pragma (msg, typeof(z[])); // (int, int, int)
>
> Tuples are special. Tuple internally keeps a compiler tuple 
> that it aliases to itself. Compiler tuples have a built-in 
> "static slice" operator that no other type has. Since Tuple 
> aliases a compiler tuple to itself internally, doing `z[]` 
> actually forwards to the compiler tuple's static slice operator

This DIP by Dicebot is relevant:
http://wiki.dlang.org/DIP63

If implemented, it can be used to overload Tuple's slice operator.


More information about the Digitalmars-d-learn mailing list