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

Mike Parker via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jun 4 19:47:18 PDT 2016


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 specified in the language. If an 
> aggregate implements both than the operator overloads are 
> privilegiated.

Only when using foreach and foreach_reverse do opApply/Reverse 
get priority. The same does not hold with retro, which only 
operates on ranges.


More information about the Digitalmars-d-learn mailing list