Instantiating template classes with default template arguments
Sean Kelly
sean at f4.ca
Wed Feb 14 11:21:52 PST 2007
Currently, this is illegal:
class C( T = int ) {}
void main() {
C val = new C;
}
However, I'm not sure I've ever completely understood the reason for it.
The intent seems clear: use class type C with the default template
arguments. From a 1000' perspective, this seems no different than the
following legal case (please note that the leading default is useless):
class C( T = int, T = int ) {}
void main() {
C!(int) val = new C!(int);
}
Resolving specializations isn't an issue either, since resolving with
with one supplied argument is the same as resolving with no supplied
arguments. I don't suppose there is any chance of this changing? And
if not, can someone please explain why?
For what it's worth, I realize that the following works:
class C( T = int ) {}
void main() {
C!() val = new C!();
}
but the "!()" just amounts to semantic noise IMO. Is it truly
necessary, given that the symbol "C" must be unique anyway? As a use
case, it would allow this:
class String( T = char ) {}
alias String!(wchar) WString;
instead of this:
class StringImpl!( T ) {}
alias StringImpl!(char) String;
alias StringImpl!(wchar) WString;
which currently makes extending library classes somewhat confusing to
new users (reference the std::basic_string issue in C++).
Sean
P.S. In writing this, I discovered that the following code compiles when
it should not:
class C( T = int, U = int ) {}
class C( T = int, U : char = int ) {}
void main()
{
auto c = new C!(int);
}
More information about the Digitalmars-d
mailing list