Switching rows with columns

via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jul 5 04:35:11 PDT 2015


On Sunday, 5 July 2015 at 00:18:18 UTC, Tanel Tagaväli wrote:
> On Saturday, 4 July 2015 at 16:29:44 UTC, Marc Schütz wrote:
>> Try std.range.transposed:
>> http://dlang.org/phobos/std_range.html#.transposed
>
> Does this work with user-defined types?
>
> I defined two structs that implement the InputRange(possibly 
> ForwardRange) interface, an integer range and a range of those 
> integer ranges.
>
> DMD tells me the "transposed" template cannot deduce function 
> from the arguments, which is a range of integer ranges.
> The template does, however, work on a two-dimensional array.
>
> The "save" method is implemented using a simple "return this", 
> could this be to blame?

This should be fine. Which of the ranges is the ForwardRange? It 
should be the range-of-ranges.

You can check which of the template constraints fails:

import std.range;
alias RangeOfRanges = typeof(myRangeOfRanges);
pragma(msg, isForwardRange!RangeOfRanges);
pragma(msg, isInputRange!(ElementType!RangeOfRanges));
pragma(msg, hasAssignableElements!RangeOfRanges);

Maybe it's the last condition, `hasAssignableElements`. I don't 
know whether that one is really necessary...


More information about the Digitalmars-d-learn mailing list