Voldemort Type Construction Error
Jonathan M Davis via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Jan 16 02:58:14 PST 2016
On Saturday, January 16, 2016 06:06:03 Kapps via Digitalmars-d-learn wrote:
> On Friday, 15 January 2016 at 20:04:47 UTC, Nordlöw wrote:
> > On Friday, 15 January 2016 at 16:51:24 UTC, Anon wrote:
> >> On Friday, 15 January 2016 at 14:04:50 UTC, Nordlöw wrote:
> >>> What have I missed?
> >>
> >> In line 126, `static struct Result()` is a template. Either
> >> drop the parens there, or change the call on line 187 to
> >> `Result!()(haystack, needles)`.
> >
> > Ahh, annoying mistake.
> >
> > Why is this allowed?
> >
> > /Per
>
> At least for functions, making them templates provides some
> benefits like inferring attributes. Not sure if it behaves the
> same way on structs by making all functions within it templates.
It does
struct S()
{
void foo()
{
}
}
void main() @safe
{
S!() s;
s.foo();
}
but having to do S!() for that rather than S is so ugly that I can't imagine
anyone actually doing it, whereas it's actually useful for functions -
particularly when you want to overload a templated function with one that
takes no template arguments. You _can_ finally overload those with normal
functions, but the overload rules don't work quite the same such that I
would normally avoid overloading a templated function with a non-templated
one.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list