D Language Foundation October 2023 Quarterly Meeting Summary

Bastiaan Veelo Bastiaan at Veelo.net
Tue Dec 12 10:34:50 UTC 2023


On Monday, 11 December 2023 at 19:55:38 UTC, Timon Gehr wrote:
> ... this successfully injects alloca into the caller's scope.
>
> ```d
> import core.stdc.stdlib:alloca;
> import std.range:ElementType;
> import core.lifetime:moveEmplace;
>
> struct VLA(T,alias len){
>     T[] storage;
>     this(R)(R initializer,return void[] 
> storage=alloca(len*T.sizeof)[0..len*T.sizeof]){
>         this.storage=cast(T[])storage;
>         foreach(ref element;this.storage){
>             assert(!initializer.empty);
>             auto init=initializer.front;
>             moveEmplace!T(init,element);
>             initializer.popFront();
>         }
>     }
>     ref T opIndex(size_t i)return{ return storage[i]; }
>     T[] opSlice()return{ return storage; }
> }
>
> auto vla(alias len,R)(R initializer,void[] 
> storage=alloca(len*ElementType!R.sizeof)[0..len*ElementType!R.sizeof]){
>     return VLA!(ElementType!R,len)(initializer,storage);
> }
>
> void main(){
>     import std.stdio,std.string,std.conv,std.range;
>     int x=readln.strip.to!int;
>     writeln(vla!x(2.repeat(x))[]);
> }
> ```

You guys are great!


More information about the Digitalmars-d-announce mailing list