Flatten a range of static arrays
Steven Schveighoffer
schveiguy at gmail.com
Fri Feb 7 21:40:36 UTC 2020
On 2/7/20 4:17 PM, Dennis wrote:
> On Friday, 7 February 2020 at 20:55:14 UTC, nullptr wrote:
>> Depending on how your range is structured, it might be possible to
>> just mark front as returning by ref to make this work.
>
> That's a good one. I can't make front() return by ref, but I can make
> front a member variable of the range struct. Only problem:
> @safe function ... cannot call @system function
> std.algorithm.iteration.joiner!(...).joiner
>
> I don't know why. I don't have time to delve into this at the moment but
> if anyone wants to try, here's a minimal testcase:
>
> ```
> import std;
>
> struct S {
> int[3] front = [10, 20, 30];
> bool empty = false;
> void popFront() {empty = true;}
> }
>
> void main() @safe {
> S.init.map!((return ref x) => x[]).joiner.writeln;
> }
> ```
> flags: -dip1000 -dip25
>
S.popFront is not @safe, and S is not a template. So no inferrence.
But I did that, and it still doesn't compile. Not sure why not. Another
fun dip1000 problem...
-Steve
More information about the Digitalmars-d-learn
mailing list