Eponymous template with full template syntax
Ali Çehreli
acehreli at yahoo.com
Mon Jul 1 15:46:55 PDT 2013
On 07/01/2013 02:10 PM, monarch_dodra wrote:
>> That is confusing.
>
> UFCS construction: Yes.
I *think* I did not know it but I can't be sure. :)
struct S
{
int i;
}
void main()
{
static assert (S(42) == 42.S);
}
It works with 2.063 (v2.064-devel-a1a1537 too).
> The rest, not so much:
>
> The idea is that once a template is "eponymous", it *fully* becomes the
> eponymous function/type/value (s). Every other function, regardless of
> public/private*, simply seizes to exist to the outside world. You can't
> make a "qualified" call to an eponymous template, because the
> "qualification" is already the call.
A single definition with the same name makes it an eponymous template. I
used to think that the template should also have a single definition.
So, currently other definitions act as implementation details of the
template. The following template sees the local S, not the module-level one:
struct S
{
int[10] i;
}
template epo(T)
{
size_t epo()
{
return S.sizeof; // <-- epo.S, not .S
}
struct S
{
int i;
}
double foo()
{
return 1.5;
}
}
void main()
{
assert(epo!int() == int.sizeof); // <-- yes, epo.S
mixin epo!int;
assert(foo() == 1.5);
}
Also note that mixing in the template is still possible but it is an
orthogonal feature anyway.
Ali
More information about the Digitalmars-d-learn
mailing list