DIP32: Uniform tuple syntax
Timon Gehr
timon.gehr at gmx.ch
Fri Mar 29 10:31:19 PDT 2013
On 03/29/2013 05:39 PM, kenji hara wrote:
> 2013/3/30 bearophile <bearophileHUGS at lycos.com
> <mailto: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.
Because of prior language limitations, not because it makes any sense!
Current operator overloading limitations mandate that it is simply not
possible to create a Phobos tuple with a sane slice operator.
> 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.
> ...
Certainly not. Creating opened tuples from closed ones is not an
operation necessarily tied to slicing.
Making an opened tuple should be an explicit operation on closed tuples.
Slicing and opening are orthogonal operations.
auto tup1 = {x.open, y.open}; // creates {1,"hi", [1,2], S(1)}
auto tup2 = {x[0..2], y[]}; // creates {{1,"hi}, {[1,2], S(1)}}
auto tup3 = {x[0..2].open, y[].open}; // creates {1,"hi", [1,2], S(1)}
More information about the Digitalmars-d
mailing list