On Mon, 13 Dec 2010 09:47:39 -0500
"Steven Schveighoffer" wrote:
> What's wrong with using opApply? You should be able to define both range
> primitives and opApply and opApply will be used when foreach is used, and
> the range primitives will be used by things like std.algorithm.
Hope opAp
On Sun, 12 Dec 2010 14:47:04 -0500, spir wrote:
Hello,
Had a nice time figuring out how to let opApply allow index iteration
like:
foreach (i, x ; collection) {}
Finally managed to do it adding 'i' everywhere:
struct S1 {
private int[] elements = [];
int opApply (int delegate (
spir wrote:
(1) In my case, I do not want to modify the range (actually the private
collection), because the type is not only about beeing a range (~
provide iteration). So that I defined the range methods, using a private
'rangeIndex slot', as (the type also maintains a 'length' slot):
On Sun, 12 Dec 2010 21:15:00 +0100
"Simen kjaeraas" wrote:
> The trick to ranges is that they modify themselves. For a simple array
> wrapper
> range this may be a way:
>
> struct wrapper( T ) {
> T[] data;
> void popFront( ) {
> data = data[1..$];
> }
> ref T fron
On Sunday 12 December 2010 12:15:00 Simen kjaeraas wrote:
> spir wrote:
> > Hello,
> >
> > Had a nice time figuring out how to let opApply allow index iteration
> >
> > like:
> > foreach (i, x ; collection) {}
> >
> > Finally managed to do it adding 'i' everywhere:
> >
> > struct S1 {
> >
spir wrote:
Hello,
Had a nice time figuring out how to let opApply allow index iteration
like:
foreach (i, x ; collection) {}
Finally managed to do it adding 'i' everywhere:
struct S1 {
private int[] elements = [];
int opApply (int delegate (ref uint, ref int) block) {
spir wrote:
PS: Also tried to make iteration work by defining slice "with no
argument" (coll[]) only, like indicated in TDPL p.381. But could not
manage to do it.
The point of coll[] is that a collection may not want to define the
range primitives itself, but rather expose a special range
On Sun, 12 Dec 2010 20:47:04 +0100
spir wrote:
> Hello,
>
> Had a nice time figuring out how to let opApply allow index iteration like:
> foreach (i, x ; collection) {}
> Finally managed to do it adding 'i' everywhere:
>
> struct S1 {
> private int[] elements = [];
> int opApply (in
Hello,
Had a nice time figuring out how to let opApply allow index iteration like:
foreach (i, x ; collection) {}
Finally managed to do it adding 'i' everywhere:
struct S1 {
private int[] elements = [];
int opApply (int delegate (ref uint, ref int) block) {
foreach (uint i, in