Either I'm just too stupid, or D is lacking something

Tom S h3r3tic at remove.mat.uni.torun.pl
Tue Jul 25 16:17:45 PDT 2006


Wolfgang Draxinger wrote:
> I'd like to write e.g the following (note the '#' indicating,
> that the template parameter "name" is to be literally replaced
> by what is written at the respective point in the template
> instanciation. The rule would be, that what follows after a '#'
> in a template must be a valid identifier and not a statement or
> expression. The usage of such a parameter within a template
> declaration would automatically limit it's usage to mixins;
> implicit mixin expansion could be assumed, but I'd discourage
> that):
> 
> template GLTexParameter(T type, GLenum Param, #name)
> {
>         T #name(T value)
>         {
>                 static if ( is ( T == GLint ) ) {
>                         glTexParameteri(Target, Param, value);
>                 } else static if ( is ( T == GLfloat ) ) {
>                         glTexParameterf(Target, Param, value);
>                 }
>                 return value;
>         }
> 
>         T #name()
>         {
>                 T value;
>                 static if ( is ( T == GLint ) ) {
>                         glGetTexParameteriv(Target, Param, &value);
>                 } else static if ( is ( T == GLfloat ) ) {
>                         glGetTexParameterfv(Target, Param, &value);
>                 }
>                 return value;
>         }
> }
> 
> class Texture
> {
>         mixin GLTexParameter!(GLint, GL_TEXTURE_MIN_FILTER, min_filter);
>         mixin GLTexParameter!(GLint, GL_TEXTURE_MAG_FILTER, mag_filter);
>         mixin GLTexParameter!(GLfloat, GL_TEXTURE_PRIORITY, priority);
> /*...*/
> }
> 
> I used a '#' since it is not being assumed a token by the D specs
> right now. I'd also like '$' like in shell scripts or Perl, but
> that's a D token already, but right now I can't remember what it
> is for, or if it's actually used.

My proposal was to add a compile - time utility to convert stings to 
identifiers: 
http://lists.puremagic.com/pipermail/digitalmars-d/2006-July/005564.html
It wouldn't need new special characters, just one new keyword and it 
could allow for some more magic.


>> btw, does your engine have some place in the net ? i'd be
>> curious to see it :)
> 
> Ever tried to make self reflecting components in
> C++, _with_ template support?

Hmmm nope...


> Rest assured, that as soon the engine is done I'm going to
> announce it's release on the D newsgroups.

Cool :)


> Check http://www.darkstargames.de/ and if you don't want to loose
> your eyes for eye cancer better do it in about 2 months and then
> go directly to http://www.darkstargames.de/even ;-)

It wasn't that bad. Probably because I have a sentiment for black 
backgrounds and bright fonts.


> In about a
> week the semester break begins and I got 3 months worth of time
> to spend only my private projects, which one of them is to make
> a new XHTML compliant homepage with sane CSS and modern look.

Great ! I'll pay you a visit later, then :)


--
Tomasz Stachowiak /+ a.k.a. h3r3tic +/



More information about the Digitalmars-d mailing list