Re: Passing iterators into functions

2020-06-25 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 25 June 2020 at 03:35:00 UTC, repr-man wrote: This seems to have to do with the fact that all iterators return their own unique type. Could someone help me understand the reason behind this design and how to remedy my situation? Ranges conform to well-defined interfaces.

Re: Passing iterators into functions

2020-06-25 Thread Ali Çehreli via Digitalmars-d-learn
Collection elements are accessed by ranges in D. Although both iterators and ranges fundamentally do the same thing (access elements). More accurately, ranges correspond to a pair iterators. On 6/24/20 8:35 PM, repr-man wrote: > auto func(R)(R r, size_t width) > if(isRandomAccessRange!R) > {

Re: Passing iterators into functions

2020-06-24 Thread Max Haughton via Digitalmars-d-learn
On Thursday, 25 June 2020 at 03:35:00 UTC, repr-man wrote: I have the code: int[5] a = [0, 1, 2, 3, 4]; int[5] b = [5, 6, 7, 8, 9]; auto x = chain(a[], b[]).chunks(5); writeln(x); It produces a range of slices as is expected: [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]] However, when I define a

Passing iterators into functions

2020-06-24 Thread repr-man via Digitalmars-d-learn
I have the code: int[5] a = [0, 1, 2, 3, 4]; int[5] b = [5, 6, 7, 8, 9]; auto x = chain(a[], b[]).chunks(5); writeln(x); It produces a range of slices as is expected: [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]] However, when I define a function as follows and pass in the result of the chain