Manipulating variables without evaluating them

Dadoum dadoum at protonmail.com
Sun May 7 17:15:00 UTC 2023


On Sunday, 7 May 2023 at 17:11:52 UTC, Dadoum wrote:
> ```d
> string crashingFunction() {
> 	assert(!__ctfe);
> 	return "OK";
> }
>
> template macroLikeTemplate(alias U) {
> 	string macroLikeTemplate() {
> 		return "" ~ U;
> 	}
> }
>
> void main()
> {
> 	macroLikeTemplate!(crashingFunction());
> }
>
> ```

By the way, this snippet could work if I just made 
`macroLikeTemplate` a regular function. But in the case I 
presented precisely, I have to iterate at compile time through 
the elements, otherwise the elements would be put in the wrong 
order, thus it can't be a function at runtime.


More information about the Digitalmars-d mailing list