Template mixins: Why is the decision to mixin made at the call site?

div0 div0 at users.sourceforge.net
Sat Aug 22 02:43:03 PDT 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Steven Schveighoffer wrote:
> On Fri, 21 Aug 2009 13:54:38 -0400, div0 <div0 at users.sourceforge.net>
> wrote:
> 
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Jarrett Billingsley wrote:
>>> On Fri, Aug 21, 2009 at 1:36 PM, div0<div0 at users.sourceforge.net> wrote:
>>>
>>> That's what he's suggesting, and it does make sense.  When you write a
>>> template, *either* it's meant to be used as a mixin, *or* it's meant
>>> to be used some other way.  Mixin in a template that wasn't meant to
>>> be a mixin or vice versa usually makes no sense.
>>
>> Hmmm.
>>
>> Not convinced by that argument, I can think of good reasons to use a
>> template as both.
>>
> 
> What you could have is similar to scope classes, that is, if you define
> a template as a mixin template, it's always meant to be a mixin (which
> is a common case).
> 
> Now, scope classes must be declared as scope when used, so does it make
> sense to require mixin templates to be called via mixin?  I'm not sure,
> it would be against what the O.P. desired, but seeing the mixin keyword
> at the usage site is a huge documentation hint.
> 
> I do see value in declaring a template as a mixin template, making it an
> error to use it as a normal template.
> 
> -Steve

That would be nice.

You can sort of bodge that at the mo.
Just stick a const method in the template, then if you try and use it
outside a class/struct the compiler barfs.

Though really that needs to change; it's inconsistent.

- --
My enormous talent is exceeded only by my outrageous laziness.
http://www.ssTk.co.uk
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iD8DBQFKj72nT9LetA9XoXwRAiBsAJ4/N0S1gzR+LaVnINd9eVHei5lHYgCfVmQi
c5FDCV9/TvqFHyY6FMhRvzg=
=R2Bs
-----END PGP SIGNATURE-----


More information about the Digitalmars-d-learn mailing list