Debug help - opDispatch - unknown member function

monkyyy crazymonkyyy at gmail.com
Tue Sep 9 14:33:16 UTC 2025


On Tuesday, 9 September 2025 at 11:57:54 UTC, Brother Bill wrote:
> On Tuesday, 9 September 2025 at 01:24:59 UTC, monkyyy wrote:
>>
>> ```
>> // I suggest a habit of avoiding simple names when generating 
>> mixin code
>> ```
>
> Please provide an example where providing simple names causes 
> 'trouble'.

```d
import std;
struct Vector(int N,T,string fields){
	static foreach(I;0..N){
		mixin("T "~fields[I]~";");
	}
	auto opDispatch(string s)(){//I suggest a habit of avoiding 
simple names when generating mixin code
		return mixin((){
			string output="tuple(";
			foreach(C;s){
				output~=C;
				output~=',';
			}
			output~=")";
			return output;
		}());
	}
}
unittest{
	Vector!(4,int,"xyzs") foo;
	foo.x=5;
	foo.y=3;
         foo.s=7;
	assert(foo.sx==tuple(7,5));
}
```


More information about the Digitalmars-d-learn mailing list