How to iterate all k-subsets of a range in a specific order?

Tommi tommitissari at hotmail.com
Fri Oct 5 02:07:55 PDT 2012


Although, the only case, where this would be
a problem is with a range of type T, where:

1) It's impossible to provide random access to T
2) T can't return a reference from its 'front' property
3) T is a finite range (not infinite)
4) 'front' property may return the same value at different indexes

Something like:

struct R
{
     int _value = 0;
     int _round = 1;

     @property bool empty() const
     {
         return _value == 100 && _round == 2;
     }

     @property int front() const
     {
         return _value;
     }

     void popFront()
     {
         if (_value == 99)
         {
             if (_round == 1)
             {
                 _value = 0;
                 _round = 2;
             }
             else
             {
                 _value = 100;
             }
         }
         else
         {
             ++_value;
         }
     }
}

Albeit, in this simple example it would be possible to provide 
random access to R, because the sequential definition of it could 
be easily replaced with an algebraic one. But for a more complex 
sequential definition, it might not be possible. So, the 
situation, where this (potential) defect of the range concept 
would be a problem, seems very rare, but it's nevertheless 
possible.



More information about the Digitalmars-d-learn mailing list