How can I have those "template instance recursive expansion" errors under control?

monkyyy crazymonkyyy at gmail.com
Sun Dec 1 21:35:43 UTC 2024


On Sunday, 1 December 2024 at 20:29:30 UTC, realhet wrote:
> 
> Update: This not works!

You have more code in that one file then I try to have in a 
*project*, so idk but if your still looking at the file, may as 
well say my thing

> But how can a standard template like CommonType or isNumeric go 
> nuts recursively?

I believe `phoboes.is*` are all *terribly* implemented, the 
"contacts" add more code that can fail for less functionality. 
WHile Im unsure about the isNumberic falls for the same pitfalls 
as say `isRange`, it wouldnt surprize me in the least

> Error: template instance `std.traits.isNumeric!(Vector!(float, 
> 3))`

I honestly hate what I can tell about your code from this one 
error message but as a bandaid add
```d
enum isNumberic(T:Vector!(S,N),S,size_T N)=true;
```

if you have any more recursive types or use other type deduction 
you will likely need to fix those as well; then ... dont do this 
type of code again, you are likely just making a recursive type 
in your opOverloads and your keep finding these sorts of issues

Avoid "contracts", make every function in structs templates even 
if its a void void function (`void foo()()=>static assert(0);` 
compiles); template wont be correct, so make things simple as 
possible with the ugly syntax and small.

---

syntax test for posterity
```d
struct data(T,size_t N){}
enum isdata(T:data!(S,N),S,size_t N)=true;
enum isdata(T)=false;

unittest{
	import std;
	isdata!(int).writeln;
	isdata!(data!(int,100)).writeln;
}
```


More information about the Digitalmars-d-learn mailing list