Parameter-less templates?
Jacob Carlborg
doob at me.com
Mon Aug 12 12:58:31 PDT 2013
On 2013-08-12 21:03, monarch_dodra wrote:
> D has introduced a pretty cool tool: templates. These are basically
> namespaces that can be instantiated by a type/alias. Mixing with them
> the notion of "eponymous" allows to do some seriously cool things with
> them.
>
> One of the things I find strange though is that they *must* be
> parameterized. This limitation seems entirely artificial to me. Why not
> allow templates without parameters, just the same way some functions
> aren't parameterized. There are useful use-cases for this:
> * Simple creation of namespaces (as opposed to non-contructible
> struct/classes)
> * Allows creating private helpers, without polluting the rest of the
> module (private functions are still callable by other functions in the
> module).
>
> So... yeah, why don't we have this?
Do you mean like:
template Foo ()
{
int a;
}
Unfortunately this doesn't work:
Foo.a = 3;
But this does:
Foo!().a = 3;
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list