On Wed, 21 Dec 2011 10:54:06 -0500, 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 ar
On Wed, 21 Dec 2011 11:34:18 -0500, pompei2 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 this to allow iterati
On Thu, Dec 22, 2011 at 12:04 AM, pompei2 wrote:
>> int delegate(int delegate(ref int)) doIter() const
>> {
>> 74 return (int delegate(ref int) dg)
>> {
>> cast(typeof(this))(this).doIter()
>> 77 (
>> 78 (ref int i)
>>
>> {
>> i
int delegate(int delegate(ref int)) doIter() const
{
74 return (int delegate(ref int) dg)
{
cast(typeof(this))(this).doIter()
77(
78 (ref int i)
{
int copy = i; dg(copy);
}
);
}
}
I see w
"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
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.
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 tho
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 it
Just remove the non-const overload. const member functions work
with mutable, immutable and const receivers.
Doing this, it compiles but it doesn't do what it should in two
ways:
1. I leave the code as-is. It compiles but "e" in the first
foreach loop in "main" is a copy, not a reference.
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'
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.
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 ov
12 matches
Mail list logo