DIP32: Uniform tuple syntax

kenji hara k.hara.pg at gmail.com
Fri Mar 29 09:39:47 PDT 2013


2013/3/30 bearophile <bearophileHUGS at lycos.com>

> kenji hara:
>
>
>  I think it will become reasonable. If you really want re-packing tuple,
>> you
>> can use {tup[0..1]}. It's quite handy.
>>
>
> This is a bad idea. It is not handy and it introduces a special case.
> Explicit is better than implicit.
>

That is "explicit". In D, opened tuple (currently it's generated from
template parameters, e.g. std.typetuple.TypeTuple) and closed tuple
(currently created by structs with alias tuple_field this; e.g.
std.typecons.Tuple) are distinct. Slice operator always returns opened
tuple.
If tup[0..1] makes closed tuple implicitly, you cannot make new flattened
tuple from other tuples.

auto x = {1,"hi"};
auto y = {[1,2], S(1)};
auto tup1 = {x[], y[]};   // creates {1,"hi", [1,2], S(1)}
auto tup2 = {x, y};   // creates {{1,"hi"}, {[1,2], S(1)}}

Under your semantics, it is impossible.

Kenji Hara.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130330/d042567f/attachment.html>


More information about the Digitalmars-d mailing list