Parameter-less templates?
Tommi
tommitissari at hotmail.com
Wed Aug 14 08:39:29 PDT 2013
On Tuesday, 13 August 2013 at 09:41:45 UTC, monarch_dodra wrote:
>
> In regards to template (I mean the actual "template"), I guess
> I wish we could either:
> 1. Allow non-parameterized templates (eg template foo {...})
> 2. Allow invoking a template without parameters (provided the
> template has 0 parameters, or default parameters), without
> doing "!()"
I think your proposal no. 1 is good, but there's a problem with
your proposal no. 2. This is current D code:
template get(int n = 1)
{
static if (n == 1) {
alias get = one;
}
else static if (n == 0) {
enum get = 0;
}
}
template one(int n)
{
enum one = 1;
}
template wrap(alias a)
{
enum wrap = a!0;
}
void main()
{
static assert(wrap!get == 0);
static assert(wrap!(get!()) == 1);
}
So, if we go with your proposal no. 2 (allow invoking a template
without a parameter list), then the meaning of 'get' in:
wrap!get
...becomes ambiguous. We could be either passing an alias to
'get', or an alias to a parameterless instantiation of template
'get', i.e. get!().
More information about the Digitalmars-d
mailing list