www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - some ideas for defaulting in templates

currently in templates we have Implicit Template Properties:

If a template has exactly one member in it, and the name of that member 
is the same as the template name, that member is assumed to be referred 
to in a template instantiation

what I would like to propose is that this be changed to

If, in a template, all public* members have the same name, and the names 
of those members are the same as the template name, those member are 
assumed to be referred to in a template instantiation. Normal 
overloading rules apply.

I don't known how this will interact with overloading groups but it 
would allow for things like this:

template Foo(T)
	T Foo(){ return T.init; }
	void Foo(){}

In the proposal the word 'public', marked with '*', needs some thought. 
The idea is to allow some members that are totally local to the 
template. these would in effect be "local variables" that could be used 
something like this

template Foo(int i, int j, int k)
	private const int i_ = Bar!(i);
	private const int j_ = Bar!(j);
	private const int k_ = Bar!(k);

	const int Foo = (i_ + j_) / k_;

private is not actually the correct word as the "locals" wold be 
accessible from outside the template. Maybe "scope" could be used.

Jan 17 2008