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

Oskar Linde oskar.lindeREM at OVEgmail.com
Tue Jul 25 02:40:17 PDT 2006


Wolfgang Draxinger skrev:
> Andrei Khropov wrote:
> 
>> Looks like we have only '@' symbol to use.
> 
> Looks nice, too.
>  
>> What you are talking about is actually more powerful
>> metaprogramming. I'm afraid it's postponed to D 2.0.
> 
> Sad, that would have made my engine's source code, especially in
> the renderer part a lot of shorter and readable.
> 
> But may I make a suggestion for D 1.0 here, that would at least
> allow usage as I have in mind, i.e. using template mixins as a
> stock function generator, by adding following rule to templates:
> 
> If a template only contains functions of the name of the
> template, and the function declarations adhere the overloading
> rules the template is a multifunction template.

Exactly this has been suggested several times before:

Eg:

http://www.digitalmars.com/d/archives/digitalmars/D/30234.html

and

http://www.digitalmars.com/d/archives/digitalmars/D/38389.html

It is a minor change, but would break existing code, so getting it 
before 1.0 would be preferred.

> Example:
> 
> template Foo (T, V, U)
> {
>         void Foo(T t,V v){...}
>         V    Foo(T t){...}
>         U    Foo(V v){...}
> };
> 
> mixin Foo!(int, bool, float) bar; // ok, no ambiguties
> 
> bar(1, 2.0);
> bool a = bar(2);
> float b = bar(true);
> 
> minxin Foo!(int, int, bool) foobar; // error: T and V conflict in
> // ambigue function parameters, that can't overload.



More information about the Digitalmars-d mailing list