Stroustrup's talk on C++0x

Walter Bright newshound1 at digitalmars.com
Sun Aug 26 11:16:49 PDT 2007


Reiner Pope wrote:
> Perhaps you mean that you can write
> 
> void Foo(T)(T* t) { ... }
> ...
> int x;
> Foo(&x);
> 
> Sure. But the following doesn't work:
> 
> void Foo(T)(T t) { ... }
> void Foo(T)(T* t) { /* different implementation for this specialisation 
>  */ }
> ...
> int x;
> Foo(x);
> Foo(&x); // ambiguous
> 
> and using template parameter specialisation, IFTI breaks.

You can write the templates as:

void Foo(T)(T t) { ... }
void Foo(T, dummy=void)(T* t) { /* different implementation for this 
specialisation
  */ }

Not so pretty, but it works.


> As to complicated predicates, I refer to the common idiom in D templates 
> which looks like the following:

Sean Kelly had a solution for that of the form:

> More often, I use an additional value parameter to specialize against:
> 
> template Foo(T, bool isValid : true = PassesSomeTest!(T)) {}



More information about the Digitalmars-d mailing list