On 04/12/2012 04:21 AM, Reid Levenick wrote:
Firstly, I had no idea where suggestions should go, and I saw a few
others here and thus here I am.

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;
}
template anotherOne( T ) {
   static if( is( T == class ) ) {
     alias long this;
   } else {
     alias int this;
   }
}

Which would reduce cruft and make it easier to read some templates, as
well as reducing maintenance.

The general idea is useful, but there are issues.

'this' is the wrong keyword for the job. A class or struct instance is very different from a template instance and the proposed usage would clash with existing and useful ones. (assuming that it would work for symbol lookups in addition to declarations)
'template' or maybe 'scope' would be superior choices.

Furthermore, what happens if such a 'this'-template is mixed in into another template?

Reply via email to