Changeset 380

Show
Ignore:
Timestamp:
07/05/08 17:14:38 (5 months ago)
Author:
FeepingCreature
Message:
  • 'Nother range improvement\!
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tools/tools/base.d

    r379 r380  
    875875    _Range_each!(T) each; 
    876876  } 
     877  bool _startIncl = true, _endExcl = true; 
     878  _Range switchMode(string P, string V, bool INC)() { 
     879    auto res = *this; 
     880    if (mixin((INC?"!":"")~"res."~P)) { 
     881      mixin("res."~P~" = "~(INC?"true":"false")~"; "); 
     882      mixin("res."~V~" "~(INC?"--":"++")~"; "); 
     883    } 
     884    return res; 
     885  } 
     886  mixin switchMode!("_startIncl", "from", true) startIncl; 
     887  mixin switchMode!("_startIncl", "from", false) startExcl; 
     888  mixin switchMode!("_endExcl", "to", false) endIncl; 
     889  mixin switchMode!("_endExcl", "to", true) endExcl; 
    877890  size_t length() { return to-from; } 
    878891  T opIndex(size_t where) { return from+cast(T) where; } 
     
    911924 
    912925struct Range { 
    913   enum Start { Incl, Excl } 
    914   enum End { Incl, Excl } 
    915   static _Range!(T) opSlice(T, U)(T from, U to, Start sm=Start.Incl, End em=End.Excl) { 
    916     if (sm != Start.Incl) from++; 
    917     if (em != End.Excl) to++; 
    918     return _Range!(T)(from, to); 
    919   } 
     926  static _Range!(T) opSlice(T, U)(T from, U to) { return _Range!(T)(from, to); } 
    920927  static _Range!(T) opIndex(T)(T to) { return _Range!(T)(Init!(T), to); } 
    921928  static void opIndexAssign(T, U)(lazy U whut, T to) { (opIndex(to))=whut; }