Re: Passing ranges around

2016-07-12 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jul 12, 2016 at 06:37:35AM +, Mike Parker via Digitalmars-d-learn wrote: > On Tuesday, 12 July 2016 at 03:57:09 UTC, Bahman Movaqar wrote: > > What should be signature of `foo` in the following piece of code? > > > > auto foo(range r) { > > // do something with the `r` > >

Re: Passing ranges around

2016-07-12 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 12 July 2016 at 07:50:34 UTC, Bahman Movaqar wrote: On 07/12/2016 11:07 AM, Mike Parker wrote: auto foo(R)(R r) { ... } That did it. Thanks. Out of curiosity, does the same pattern apply to functions which take `tuple`s as input arguments? It's just a function template. It's w

Re: Passing ranges around

2016-07-12 Thread Bahman Movaqar via Digitalmars-d-learn
On 07/12/2016 11:07 AM, Mike Parker wrote: > auto foo(R)(R r) { ... } That did it. Thanks. Out of curiosity, does the same pattern apply to functions which take `tuple`s as input arguments? -- Bahman

Re: Passing ranges around

2016-07-11 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 12 July 2016 at 03:57:09 UTC, Bahman Movaqar wrote: What should be signature of `foo` in the following piece of code? auto foo(range r) { // do something with the `r` } void main() { foo([1,2,3].map!(x => x*x)); } auto foo(R)(R r) { ... }

Passing ranges around

2016-07-11 Thread Bahman Movaqar via Digitalmars-d-learn
What should be signature of `foo` in the following piece of code? auto foo(range r) { // do something with the `r` } void main() { foo([1,2,3].map!(x => x*x)); } Right now I use `.array` to convert the range before passing: auto foo(int[] r) { // do someth