Why tuples are not ranges?

Alex sascha.orlov at gmail.com
Thu Jun 28 16:02:59 UTC 2018


On Thursday, 28 June 2018 at 14:35:33 UTC, Mr.Bingo wrote:
> Seems like it would unify things quite a bit.

Yeah... this is, because you can't popFront on a tuple, as the 
amount of entries is fixed. You can, however, popFront on every 
range.

But as Timoses wrote you can easily make a range out of a tuple, 
for example by slicing:

´´´
import std.typecons, std.range, std.array, std.algorithm, 
std.stdio;

     void main()
     {
         auto t = tuple(3,4,5,6);
		auto m = [t[]];
         writeln(m.map!(a => 3*a).sum());
     }
´´´


More information about the Digitalmars-d-learn mailing list