digitalmars.D - Random access range
- zeljkog (14/14) Mar 08 2012 import std.stdio;
- Steven Schveighoffer (4/18) Mar 08 2012 No, a random access range must also be a bidirectional and input range. ...
- Xinok (16/30) Mar 08 2012 struct N(T){
import std.stdio; struct Rar{ int[] data = [1,3,5]; int length = 3; ref int opIndex(int i){ return data[i];} } void main() { Rar x; foreach (e; x) writeln(e); } Error: invalid foreach aggregate x ---- Is'nt Rar valid random access range?
Mar 08 2012
On Thu, 08 Mar 2012 11:43:24 -0500, zeljkog <zeljkog home.com> wrote:import std.stdio; struct Rar{ int[] data = [1,3,5]; int length = 3; ref int opIndex(int i){ return data[i];} } void main() { Rar x; foreach (e; x) writeln(e); } Error: invalid foreach aggregate x ---- Is'nt Rar valid random access range?No, a random access range must also be a bidirectional and input range. You need the standard range primitives. -Steve
Mar 08 2012
On Thursday, 8 March 2012 at 16:43:25 UTC, zeljkog wrote:import std.stdio; struct Rar{ int[] data = [1,3,5]; int length = 3; ref int opIndex(int i){ return data[i];} } void main() { Rar x; foreach (e; x) writeln(e); } Error: invalid foreach aggregate x ---- Is'nt Rar valid random access range?struct N(T){ T[] arr; this(T[] other){ arr = other; } this(N other){ arr = other.arr; } // The declarations below are required // The property tag is also required ref T opIndex(size_t i){ return arr[i]; } property size_t length(){ return arr.length; } property ref T front(){ return arr.front; } property ref T back(){ return arr.back; } void popFront(){ arr.popFront(); } void popBack(){ arr.popBack(); } property bool empty(){ return arr.empty; } property N save(){ return N(arr); } }
Mar 08 2012