Russel Winder , dans le message (digitalmars.D:173102), a écrit : > > --=-aHxuwwF1pyt7fCGYFQXP > Content-Type: text/plain; charset="UTF-8" > Content-Transfer-Encoding: quoted-printable > > On Tue, 2012-07-24 at 13:56 -0400, Andrei Alexandrescu wrote: > [=E2=80=A6] >> The example is: >>=20 >> int[] arr1 =3D [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]; >> auto s =3D take(arr1, 5); >> assert(s.length =3D=3D 5); >> assert(s[4] =3D=3D 5); >> assert(equal(s, [ 1, 2, 3, 4, 5 ][])); >>=20 >> Were you referring to this? Example code does not need to be generic,=20 >> and in this case it's fine if the code relies on random access because= > =20 >> it uses an array of integers. > > That's the one. > > s[4] relies on the fact that arr1 is an array: > > ( takeExactly ( recurrence ! ( "a[n-1] + a[n-2]" ) ( 0L , 1L ) , cast > ( size_t ) ( n + 1 ) ) ) [ n ] > > fails with operator [] not defined, I find I have to:
This is expressed in the doc, not in the example: > If the range offers random access and length, Take offers them as > well. recurrence does not offer random access, so take!recurrence does not. You may try to make sentence this clearer, but it's pretty clear to me. -- Christophe
