foreach ref very broken: fails to call front(val)
Ali Çehreli
acehreli at yahoo.com
Tue Jul 10 00:39:11 PDT 2012
On 07/10/2012 12:21 AM, kenji hara wrote:
> There are two problems:
>
> 1. std.container.Array.(front, back, opIndex, ...) doesn't return its
> elements by ref.
It's not that obvious to me. The following picture should supposedly
provide references to elements:
The latter of the following pair of Array.Range.front() should be used
in the foreach body:
@property T front()
{
enforce(!empty);
return _outer[_a];
}
@property void front(T value)
{
enforce(!empty);
_outer[_a] = move(value);
}
There, _outer is the Array itself. And Array.opIndexAssign() seems to be
doing the right thing:
void opIndexAssign(T value, size_t i)
{
enforce(_data.RefCounted.isInitialized);
_data._payload[i] = value;
}
Ali
More information about the Digitalmars-d
mailing list