Flatten a range of static arrays
    Steven Schveighoffer 
    schveiguy at gmail.com
       
    Sat Feb  8 00:14:41 UTC 2020
    
    
  
On 2/7/20 6:10 PM, nullptr wrote:
> ```
> import std;
> 
> struct SomeRange
> {
>      int[3] val;
> 
>      enum empty = false;
> 
>      auto popFront() @safe {}
> 
>      ref auto front() @safe
>      {
>          return val;
>      }
> }
> 
> void main() @safe
> {
>      SomeRange().take(10).map!((return ref x) => x[]).joiner.writeln;
> }
> ```
> 
> I don't know how applicable this is to your use case, but this code will 
> compile and run under -dip1000.
I tried the AST button. for the front function I got:
return pure nothrow @nogc ref @safe int[3] front() return
Note the duplicate return attributes. When I type that in, it doesn't 
compile, the return at the front is invalid.
When I remove that return, I get a safety error. So something is weird 
about how the attributes are inferred. Either there is some magic 
attribute not being printed, or an attribute that can't be specified 
manually, or it's a bug.
-Steve
    
    
More information about the Digitalmars-d-learn
mailing list