Difference between input range and forward range

Shachar Shemesh via Digitalmars-d digitalmars-d at puremagic.com
Tue Nov 10 06:28:14 PST 2015

Please consider the following program:
import std.stdio;
import std.range;

struct Range {
     int a;

     @disable this(this);
     int front() {
         return a;

     void popFront() {

     bool empty() {
         return a<=0;

void main()
     pragma(msg, isInputRange!Range);
     pragma(msg, isForwardRange!Range);
     auto r = Range(5);

     foreach( i; r ) {

     foreach( i; r ) {

It seems that "foreach" requires that the range be copyable, in direct 
contradiction to the fact that Range is not a forward range.

Removing the @disable, the program compiles and run, but prints the 
range twice instead of once.

If you couple that with the extremely amorphous definition of "save" for 
forward ranges, there seems to be quite a confusion between the two.

Am I missing something?


More information about the Digitalmars-d mailing list