How to specity a list of fields with default to a mixin template?

monkyyy crazymonkyyy at gmail.com
Sun Mar 2 23:24:58 UTC 2025


On Sunday, 2 March 2025 at 19:31:06 UTC, realhet wrote:
> Anyone have an idea?

Such things are extremely discouraged and I could suggest maybe 3 
hacks

> But I unable to find a way to parse this declaration in the 
> scope where my types are.

```d
--- foo.d
import std;
public import bar;
myint fizz;

import foobar;
unittest{
	makeconstructor!("myint buzz;") hello;
	//hello.importstring.writeln;
	hello.buzz=3;
}
--- bar.d

alias myint=int;

--- foobar.d

string parseimport(string s){
	return s[0..$-2];
}
	
template makeconstructor(string s,string file=__FILE__){
	struct makeconstructor{
	//enum importstring="import "~file.parseimport~";";
	mixin("import "~file.parseimport~";");
	mixin(s);
	}
}
```

if its global scope you have this option


More information about the Digitalmars-d-learn mailing list