Re: writing iterators without code duplication. inout?

2012-01-07 Thread Steven Schveighoffer
On Wed, 21 Dec 2011 11:34:18 -0500, pompei2 pomp...@gmail.com wrote: On Wednesday, 21 December 2011 at 16:05:24 UTC, Trass3r wrote: Can't really answer your original question, but 1. Why don't you use opApply? 2. Why do you use ref int even in the const version? 3. You could also use alias

Re: writing iterators without code duplication. inout?

2012-01-07 Thread Steven Schveighoffer
On Wed, 21 Dec 2011 10:54:06 -0500, pompei2 pomp...@gmail.com wrote: Hello. I want to add the option to iterate objects of my class using foreach. I need them to be iterable as view-only const and as mutable too. I would prefer to iterate using the return a delegate but if that's not

writing iterators without code duplication. inout?

2011-12-21 Thread pompei2
Hello. I want to add the option to iterate objects of my class using foreach. I need them to be iterable as view-only const and as mutable too. I would prefer to iterate using the return a delegate but if that's not possible, ranges are fine too. Also, I'd prefer a template-less solution

Re: writing iterators without code duplication. inout?

2011-12-21 Thread Trass3r
Can't really answer your original question, but 1. Why don't you use opApply? 2. Why do you use ref int even in the const version? 3. You could also use alias this to allow iteration, don't know if that's what you want in general though.

Re: writing iterators without code duplication. inout?

2011-12-21 Thread Timon Gehr
On 12/21/2011 04:54 PM, pompei2 wrote: Hello. I want to add the option to iterate objects of my class using foreach. I need them to be iterable as view-only const and as mutable too. I would prefer to iterate using the return a delegate but if that's not possible, ranges are fine too. Also, I'd

Re: writing iterators without code duplication. inout?

2011-12-21 Thread Jakob Ovrum
On Wednesday, 21 December 2011 at 16:31:01 UTC, Jakob Ovrum wrote: On Wednesday, 21 December 2011 at 16:07:55 UTC, Timon Gehr wrote: Just remove the non-const overload. const member functions work with mutable, immutable and const receivers. The const version does not allow using 'ref' when

Re: writing iterators without code duplication. inout?

2011-12-21 Thread pompei2
On Wednesday, 21 December 2011 at 16:05:24 UTC, Trass3r wrote: Can't really answer your original question, but 1. Why don't you use opApply? 2. Why do you use ref int even in the const version? 3. You could also use alias this to allow iteration, don't know if that's what you want in general

Re: writing iterators without code duplication. inout?

2011-12-21 Thread Jakob Ovrum
On Wednesday, 21 December 2011 at 16:07:55 UTC, Timon Gehr wrote: Just remove the non-const overload. const member functions work with mutable, immutable and const receivers. The const version does not allow using 'ref' when iterating.

Re: writing iterators without code duplication. inout?

2011-12-21 Thread Christophe
pompei2 , dans le message (digitalmars.D.learn:31164), a écrit : This is what I have, which works but has severe code duplication. I hoped inout would help me here, but I just can't figure it out. I also gave a try to ranges, but same thing again: I can only get it to work if I define my