Template with default parameter
Ali Çehreli
acehreli at yahoo.com
Fri Mar 11 12:35:38 UTC 2022
On 3/11/22 04:01, Andrey Zherikov wrote:
> There is some inconsistency between templates and template functions as
> this works as I want to:
> ```d
> import std.stdio;
>
> void f(int i=3)()
> {
> writeln(i);
> }
>
> void main()
> {
> f!1; // 1
> f!(); // 3
> f; // 3
> }
> ```
Reduced:
template T(int i = 3) {
enum value = i;
}
void main() {
pragma(msg, T!().value); // Requires T!()
}
The same inconsistency exists for user-defined type templates as well:
struct S(int i = 3) {
}
void main() {
S!() s; // Requires S!()
}
There has been requests to remove this inconsistency. Might be in bugzilla.
Ali
More information about the Digitalmars-d-learn
mailing list