An idea to improve eponymous templates

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Apr 11 19:56:05 PDT 2012


On Thu, Apr 12, 2012 at 04:21:45AM +0200, Reid Levenick wrote:
> Firstly, I had no idea where suggestions should go, and I saw a few
> others here and thus here I am.

AFAIK this is as good a place as any other.


> I was writing some code that depended heavily on my own eponymous
> templates, and decided to change the names of some of them to make
> them more self-documenting. However, after changing the name, I
> encountered a long stream of unintelligible errors (to me, I haven't
> been using D for a long time) about template instances.
> 
> So, my idea is that the 'this' keyword could be used in templates as a
> shortcut for eponymous templates, allowing code like this
> 
> template anEponymousTemplate( size_t whatever ) {
>   enum this = whatever * 2;
> }
[...]

+1. I like this idea. In fact, I've thought about proposing it before.
:-) I don't like the idea of having to repeatedly retype the template
name. I mean, the compiler already implicitly translates:

	int myfunc(T)(T args) { ... }

to:

	template myfunc(T) {
		int myfunc(T args) { ... }
	}

and nowadays pretty much *nobody* writes it the second way anymore.

Having to repeatedly type the same identifiers is one of the things that
puts me off so much about Java. Especially with its proliferation of
overly long identifiers (and their respective *Wrappers thereof).


T

-- 
The richest man is not he who has the most, but he who needs the least.


More information about the Digitalmars-d mailing list