On 06/19/2012 02:54 PM, Christophe Travert wrote:
Jonathan M Davis , dans le message (digitalmars.D:170054), a écrit :
I'd propose to always add a bool template parameter (maybe isConst?) to
the range since most of the write-functionality can be "removed" by a
static if statement in order to make the range read-only.

Any suggestions?

Boolean parameters are very obscure.
How do you guess what is the meaning of false in:
Range!false;

Range!IsConst.no would be better.

struct ArrayRange(bool isConst) {...}
alias ArrayRange!false Range;
alias ArrayRange!true ConstRange;

Range and ConstRange seems a good thing to have, just like c++
containers have iterator and const_iterator.


Something along these lines seems to be a superior design:

struct ArrayRange(T){ ... }

class Array(T){
    ...
    ArrayRange!T opSlice(){ ... }
    ArrayRange!(const(T)) opSlice()const{ ... }
    ArrayRange!(immutable(T)) opSlice()immutable{ ... }
    ...
}

(Where the opSlice functions can be generated automatically.)

Reply via email to