std.v2 builder pattern replacement
monkyyy
crazymonkyyy at gmail.com
Wed Jul 27 17:00:40 UTC 2022
On Wednesday, 27 July 2022 at 09:15:28 UTC, FeepingCreature wrote:
> This only works with constants;
```d
auto withMe(string mixin_,Me,T...)(Me me,T arg){
with(me){
mixin(mixin_);
}
import std.algorithm;
static if(!mixin_.canFind("return")){
return me;
}
}
struct foo{
float f;
int uselessfield=1337;
bool b;
}
alias biuldfoo=withMe!(q{f=arg[1];b=arg[0];},foo,bool,float);
void main(){
import std.stdio;
bool t=true;
float fourtwenty=4.20;
foo().withMe!q{f=arg[1];b=arg[0];}(t,fourtwenty).writeln;
foo().biuldfoo(t,fourtwenty).writeln;
}```
More information about the Digitalmars-d
mailing list