Why tuples are not ranges?

Ali Çehreli acehreli at yahoo.com
Fri Jun 29 17:35:02 UTC 2018


On 06/28/2018 11:10 PM, Jonathan M Davis wrote:
 > On Friday, June 29, 2018 05:52:03 Alex via Digitalmars-d-learn wrote:

 >> Wouldn't this be weird from the semantic view?

I agree with all your concerns. The fact that Meta decided to make the 
element type Algebraic!T as opposed to my CommonType!T choice is another 
semantic problem.

 > It wouldn't make any sense to turn a Tuple into a range. However, if 
all of
 > the values are of the same type, it might make sense to create a 
range from
 > each of the values in the Tuple.

I went a step further and used CommonType!T.

 > a helper function could be created that takes a Tuple and
 > returns a range which wraps it.

That's what my example did (with added bugs like 'length' being an enum 
by mistake).

 > And at that point, talking about
 > getting a range over a Tuple is basically the same thing as talking about
 > creating a range from an arbitrary struct whose members all happen to 
have
 > the same type - and that would be pretty weird.

Agreed.

Ali



More information about the Digitalmars-d-learn mailing list