digitalmars.D.learn - Switching rows with columns
- "Tanel =?UTF-8?B?VGFnYXbDpGxpIg==?= <tanel58 hotmail.com> (11/11) Jul 04 2015 I have a range of ranges and need to change it so the elements
- "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> (3/14) Jul 04 2015 Try std.range.transposed:
- "Tanel =?UTF-8?B?VGFnYXbDpGxpIg==?= <tanel58 hotmail.com> (10/12) Jul 04 2015 Does this work with user-defined types?
- "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> (11/23) Jul 05 2015 This should be fine. Which of the ranges is the ForwardRange? It
- "Tanel =?UTF-8?B?VGFnYXbDpGxpIg==?= <tanel58 hotmail.com> (5/7) Jul 05 2015 It probably is. The last check returned false.
I have a range of ranges and need to change it so the elements are column-aligned instead of row-aligned. For example, [[1, 2, 3], [4, 5, 6], [7, 8, 9]] would change into [[1, 4, 7], [2, 5, 8], [3, 6, 0]]. Can I even do this with ranges, and if so, how?
Jul 04 2015
On Saturday, 4 July 2015 at 15:28:56 UTC, Tanel Tagaväli wrote:I have a range of ranges and need to change it so the elements are column-aligned instead of row-aligned. For example, [[1, 2, 3], [4, 5, 6], [7, 8, 9]] would change into [[1, 4, 7], [2, 5, 8], [3, 6, 0]]. Can I even do this with ranges, and if so, how?Try std.range.transposed:
Jul 04 2015
On Saturday, 4 July 2015 at 16:29:44 UTC, Marc Schütz wrote:Try std.range.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?
Jul 04 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: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...Try std.range.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?
Jul 05 2015
On Sunday, 5 July 2015 at 11:35:14 UTC, Marc Schütz wrote:Maybe it's the last condition, `hasAssignableElements`. I don't know whether that one is really necessary...It probably is. The last check returned false. Since I already would have to implement "r.front = ", I'll just use arrays. Thanks for the help.
Jul 05 2015