template auto value

Timon Gehr timon.gehr at gmx.ch
Sat Mar 3 00:25:21 UTC 2018


On 03.03.2018 01:20, H. S. Teoh wrote:
> On Fri, Mar 02, 2018 at 11:51:08PM +0000, Jonathan Marler via Digitalmars-d wrote:
>> I believe I found small hole in template parameter semantics.
>> [...] you can't create a template that accepts a value of any type.
> Not true:
> 
> 	template counterexample(alias T) {}
> 
> 	int x;
> 	string s;
> 	alias U = counterexample!x;	// OK
> 	alias V = counterexample!1;	// OK
> 	alias W = counterexample!"yup";	// OK
> 	alias X = counterexample!s;	// OK
> 
> 	alias Z = counterexample!int;	// NG
> 
> The last one fails because a value is expected, not a type.

No, it fails because a "symbol" is expected, not a basic type. There 
really is no good reason why int should not be accepted -- a class or 
struct type would be accepted. IIRC Walter has agreed to this, and it's 
just pending implementation.


More information about the Digitalmars-d mailing list