Re: Is it possible to use a template to choose between foreach and foreach_reverse?

2016-06-04 Thread Mike Parker via Digitalmars-d-learn
On Saturday, 4 June 2016 at 21:52:31 UTC, AbstractGuy wrote: On Saturday, 4 June 2016 at 17:16:45 UTC, pineapple wrote: Won't this pattern fail if items is a type implementing opApply and/or opApplyReverse? opApply/ApplyReverse predates the detection of the input/bidir range primitives. It's

Re: Is it possible to use a template to choose between foreach and foreach_reverse?

2016-06-04 Thread AbstractGuy via Digitalmars-d-learn
On Saturday, 4 June 2016 at 17:16:45 UTC, pineapple wrote: Won't this pattern fail if items is a type implementing opApply and/or opApplyReverse? opApply/ApplyReverse predates the detection of the input/bidir range primitives. It's specified in the language. If an aggregate implements both

Re: Is it possible to use a template to choose between foreach and foreach_reverse?

2016-06-04 Thread Ali Çehreli via Digitalmars-d-learn
On 06/04/2016 07:32 AM, pineapple wrote: > It would be fantastic if I could write this - > > static if(forward){ > foreach(item; items) dostuff(); > }else{ > foreach_reverse(item; items) dostuff(); > } > > as something like this - > > foreach!forward(item; items)

Re: Is it possible to use a template to choose between foreach and foreach_reverse?

2016-06-04 Thread pineapple via Digitalmars-d-learn
On Saturday, 4 June 2016 at 15:43:01 UTC, Mihail K wrote: As far as I recall, foreach_reverse is deprecated in favour of range operations. ie. import std.algorithm, std.range; static if(forward) { items.each!(item => doStuff()); } else { items.retro.each!(item =>

Re: Is it possible to use a template to choose between foreach and foreach_reverse?

2016-06-04 Thread Mihail K via Digitalmars-d-learn
On Saturday, 4 June 2016 at 14:32:23 UTC, pineapple wrote: It would be fantastic if I could write this - static if(forward){ foreach(item; items) dostuff(); }else{ foreach_reverse(item; items) dostuff(); } as something like this - foreach!forward(item; items)

Is it possible to use a template to choose between foreach and foreach_reverse?

2016-06-04 Thread pineapple via Digitalmars-d-learn
It would be fantastic if I could write this - static if(forward){ foreach(item; items) dostuff(); }else{ foreach_reverse(item; items) dostuff(); } as something like this - foreach!forward(item; items) dostuff(); Is there any way to accomplish this?