What's wrong with my usage of std.algorithm.map in this code example?

Chris via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed May 25 07:39:32 PDT 2016


On Wednesday, 25 May 2016 at 14:32:11 UTC, ag0aep6g wrote:
> On 05/25/2016 03:27 PM, Chris wrote:
>> Why can the tuple be iterated with foreach, as in my quick 
>> fix, and
>> indexed with tuple[0..], but is not accepted as a range? What 
>> are the
>> differences?
>
> popFront doesn't make sense with a tuple (aka expression list). 
> When you remove the first element of a tuple, you get another 
> tuple of a different type, but popFront can't change the type 
> of the range.
>
> In code:
>
> ----
> void main()
> {
>     import std.meta: AliasSeq;
>     AliasSeq!(int, int, int) tuple = AliasSeq!(1, 2, 3);
>     tuple.popFront(); /* How would this be implemented? Would 
> have to change tuple's type to AliasSeq!(int, int). */
> }
> ----
>
>> Is there a way to rangify a tuple?
>
> std.range.only:
>
> ----
> void main()
> {
>     import std.meta: AliasSeq;
>     import std.range: only;
>     AliasSeq!(int, int, int) tuple = AliasSeq!(1, 2, 3);
>     auto range = only(tuple);
>     range.popFront(); /* ok */
> }
> ----

I see. Maybe it would be worth adding a wrapper to typecons.Tuple 
or std.range that helps to rangify tuples. I cannot think of any 
use case right now. I never needed this and in the example that 
started this thread, it would keep the function from converting 
mixed tuples (cf. my example above).


More information about the Digitalmars-d-learn mailing list