September 13, 2004
Craig Black wrote:

> In C++ the -> operator is overloaded for iterators in order to access
> nodes
> in a container.  How does D do this?  Would it be useful to have something
> similar to a mixin that was a pointer?
> 
> (I'm not a D programmer so forgive me if my syntax is off.)
> Something like:
> 
> template ListNode(T)
> {
>   mixin T;
>   ListNode *next, *previos;
> }
> 
> template ListIterator(T)
> {
>   mixin ListNode(T) *node;
> }

A mixin is basically just a way of saving typing so it is independent of operator overloading. To "dereference" an iterator I'd either make a property and/or deal with slices instead of iterators and use array indexing expressions. In MinTL instead of writing *i to dereference an iterator one writes i[0] to dereference the first item in the slice. D doesn't support overloading the dereferencing operators "." or "*".

Usually, though, one just foreach'es over the container and avoid iterators entirely.

-Ben
July 26, 2012
On 9/9/04 10:44 PM, Ben Hinkle wrote:
> Here I thought mixins were a pain but I've been going through mintl and
> experimenting with consolidating shared code into mixins and they've been
> working great. I'd like to really say thanks to Walter for adding mixins. I
> wasn't convinced before but I'm really liking them now. In my sandbox mintl
> now has three mixins:
> - one for opCat-like functions (6 functions)
> - one for opApply overloads and variations (8 functions)
> - one for backwards opApply and toSeq variations (5 functions)
>
> They cut way down on the cut-and-paste aspect of mintl that had been
> bothering me. It's to the point where there isn't any "boilerplate" code in
> the individual containers.
>
> I've found using public mixins to be more successful that using private
> mixins. Private symbols seem to trip up mixins. The rules are probably
> obvious but I haven't taken the time to figure them out so I've gotten in
> the habit of only mixing in public declarations and having the mixins only
> reference public symbols.
>
> -Ben

Nice work, and good discussion in this thread. A great next step would be to write about how you all use mixins (both of the code and string kind) in blogs and articles.

Andrei
July 26, 2012
On 7/26/12 10:37 AM, Andrei Alexandrescu wrote:
> Nice work, and good discussion in this thread. A great next step would
> be to write about how you all use mixins (both of the code and string
> kind) in blogs and articles.

Heh, I replied to a post from 2004 hoping to get to the earliest in the "I just have to say that string mixins rock" thread.

Andrei


July 27, 2012
On Jul 26, 2012, at 7:38 AM, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote:

> On 7/26/12 10:37 AM, Andrei Alexandrescu wrote:
>> Nice work, and good discussion in this thread. A great next step would be to write about how you all use mixins (both of the code and string kind) in blogs and articles.
> 
> Heh, I replied to a post from 2004 hoping to get to the earliest in the "I just have to say that string mixins rock" thread.

Apparently, mixins have rocked since 2004 :-)
1 2
Next ›   Last »