Taking the address of an eponymous template

Arafel via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jul 31 02:44:43 PDT 2017


Hi!

I want to create a delegate out of a method that happens to be an 
eponymous (nested) template, like this:

```
class C {
	void foo() {}
	void bar(string S)() { }
	template baz(string S) {
		void baz()() {
		}
	}
}

void main() {
	C c = new C();
	void delegate() aFoo = &c.foo;
	void delegate() aBar = &c.bar!"a";
	void delegate() aBaz = &c.baz!"a"; // This doesn't compile.
}
```

If I try &c.baz!"a".baz it doesn't work either (I get a different error 
message.

Do you know if this works (and if so, what should I do), or if it's 
supposed to?

Of course in this case I don't need to use an eponymous template at all, 
bit it's just a simplification to try to get everything else out of the 
way...

In case anyone is interested, the real case is something more like this:

```
class C {
	template baz(args...) if (someCondition!args) {
		void baz(this T) {
		}
	}
}
```

As far as I know, that's the only way to combine a "this" template 
parameter with variadic template parameters.

As usual, thanks for the great support, D hast got a great community!

P.S.: When the function inside the eponymous template is not templated 
itself, then it does work:

´´´
class C {
	template baz(string S) {
		void baz() {
		}
	}
}

void main() {
	C c = new C();
	auto aBaZ = &c.baz!"a";
}
´´´



More information about the Digitalmars-d-learn mailing list