Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changeset 1704

Show
Ignore:
Timestamp:
07/01/10 02:51:24 (14 years ago)
Author:
dsimcha
Message:

@property cleanup for std.range.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/phobos/std/range.d

    r1698 r1704  
    633633private: 
    634634    R _input; 
    635635    enum bool byRef = is(typeof(&(R.init.front()))); 
    636636 
    637637public: 
    638638    alias R Source; 
    639639 
    640640/** 
    641641Forwards to $(D _input.empty). 
    642642 */ 
    643     bool empty() 
     643    @property bool empty() 
    644644    { 
    645645        return _input.empty; 
    646646    } 
    647647 
    648648/** 
    649649Returns a copy of $(D this). 
    650650 */ 
    651651    @property Retro save() 
    652652    { 
    653653        return Retro(_input.save); 
     
    831831    { 
    832832        @property Stride save() 
    833833        { 
    834834            return Stride(_input.save, _n); 
    835835        } 
    836836    } 
    837837 
    838838/** 
    839839Forwards to $(D _input.empty). 
    840840 */ 
    841     bool empty() 
     841    @property bool empty() 
    842842    { 
    843843        return _input.empty; 
    844844    } 
    845845 
    846846/** 
    847847@@@ 
    848848 */ 
    849849    void popFront() 
    850850    { 
    851851        static if (isRandomAccessRange!(R) && hasLength!(R) && hasSlicing!(R)) 
     
    879879                { 
    880880                    if (_input.empty) break; 
    881881                    _input.popBack; 
    882882                } 
    883883            } 
    884884        } 
    885885 
    886886/** 
    887887Forwards to $(D _input.front). 
    888888 */ 
    889     ref ElementType!(R) front() 
     889    @property ref ElementType!(R) front() 
    890890    { 
    891891        return _input.front; 
    892892    } 
    893893 
    894894/** 
    895895Forwards to $(D _input.back) after getting rid of any slack items. 
    896896 */ 
    897897    static if(isBidirectionalRange!(R) && hasLength!(R)) 
    898898    { 
    899         ref ElementType!(R) back() 
     899        @property ref ElementType!(R) back() 
    900900        { 
    901901            return _input.back; 
    902902        } 
    903903    } 
    904904 
    905905/** 
    906906Forwards to $(D _input[_input.length - n + 1]). Defined only if $(D R) 
    907907is a random access range and if $(D R) defines $(D R.length). 
    908908 */ 
    909909    static if (isRandomAccessRange!(R) && hasLength!(R)) 
     
    10251025        alias RvalueElementType ElementType; 
    10261026 
    10271027    this(R input) 
    10281028    { 
    10291029        foreach (i, v; input) 
    10301030        { 
    10311031            _input.field[i] = v; 
    10321032        } 
    10331033    } 
    10341034 
    1035     bool empty() 
     1035    @property bool empty() 
    10361036    { 
    10371037        foreach (i, Unused; R) 
    10381038        { 
    10391039            if (!_input.field[i].empty) return false; 
    10401040        } 
    10411041        return true; 
    10421042    } 
    10431043 
    10441044    static if (allSatisfy!(isForwardRange, R)) 
    10451045        ChainImpl save() 
     
    13281328 */ 
    13291329    ref Radial opSlice() 
    13301330    { 
    13311331        return this; 
    13321332    } 
    13331333 
    13341334/** 
    13351335Range primitive operation that returns $(D true) iff there are no more 
    13361336elements to be iterated. 
    13371337 */ 
    1338     bool empty() 
     1338    @property bool empty() 
    13391339    { 
    13401340        return _low.empty && _up.empty; 
    13411341    } 
    13421342 
    13431343/** 
    13441344Range primitive operation that advances the range to its next 
    13451345element. 
    13461346 */ 
    13471347    void popFront() 
    13481348    { 
     
    13691369            if (!_up.empty) _up.popFront; 
    13701370            if (!_low.empty) _low.popBack; 
    13711371            if (!_low.empty) _upIsActive = false; 
    13721372        } 
    13731373    } 
    13741374 
    13751375/** 
    13761376Range primitive operation that returns the currently iterated 
    13771377element. Throws if the range is empty. 
    13781378 */ 
    1379     ref ElementType!(R) front() 
     1379    @property ref ElementType!(R) front() 
    13801380    { 
    13811381        enforce(!empty, "Calling front() against an empty " 
    13821382                ~typeof(this).stringof); 
    13831383        if (!_upIsActive) 
    13841384        { 
    13851385            // @@@ Damndest thing... removing the enforce below causes 
    13861386            // a segfault in release unittest 
    13871387            enforce(!_low.empty); 
    13881388            return _low.back; 
    13891389        } 
     
    14501450    enum bool byRef = is(typeof(&_input.front) == ElementType!(R)*); 
    14511451 
    14521452public: 
    14531453    alias R Source; 
    14541454 
    14551455    static if (byRef) 
    14561456        alias ref .ElementType!(R) ElementType; 
    14571457    else 
    14581458        alias .ElementType!(R) ElementType; 
    14591459 
    1460     bool empty() 
     1460    @property bool empty() 
    14611461    { 
    14621462        return _maxAvailable == 0 || original.empty; 
    14631463    } 
    14641464 
    14651465    static if (isForwardRange!R) 
    14661466        @property Take save() 
    14671467        { 
    14681468            return Take(original.save, _maxAvailable); 
    14691469        } 
    14701470 
     
    17341734Tip: This is a great way to implement simple circular buffers. 
    17351735 */ 
    17361736struct Cycle(R) if (isForwardRange!(R) && !isInfinite!(R)) 
    17371737{ 
    17381738    static if (isRandomAccessRange!(R) && hasLength!(R)) 
    17391739    { 
    17401740        R _original; 
    17411741        size_t _index; 
    17421742        this(R input, size_t index = 0) { _original = input; _index = index; } 
    17431743        /// Range primitive implementations. 
    1744         ref ElementType!(R) front() 
     1744        @property ref ElementType!(R) front() 
    17451745        { 
    17461746            return _original[_index % _original.length]; 
    17471747        } 
    17481748        /// Ditto 
    17491749        enum bool empty = false; 
    17501750        /// Ditto 
    17511751        void popFront() { ++_index; } 
    17521752        ref ElementType!(R) opIndex(size_t n) 
    17531753        { 
    17541754            return _original[(n + _index) % _original.length]; 
     
    17561756        /// Ditto 
    17571757        @property Cycle!(R) save() { 
    17581758            return Cycle!(R)(this._original.save, this._index); 
    17591759        } 
    17601760    } 
    17611761    else 
    17621762    { 
    17631763        R _original, _current; 
    17641764        this(R input) { _original = input; _current = input.save; } 
    17651765        /// Range primitive implementations. 
    1766         ref ElementType!(R) front() { return _current.front; } 
     1766        @property ref ElementType!(R) front() { return _current.front; } 
    17671767        /// Ditto 
    17681768        static if (isBidirectionalRange!(R)) 
    1769             ref ElementType!(R) back() { return _current.back; } 
     1769            @property ref ElementType!(R) back() { return _current.back; } 
    17701770        /// Ditto 
    17711771        enum bool empty = false; 
    17721772        /// Ditto 
    17731773        void popFront() 
    17741774        { 
    17751775            _current.popFront; 
    17761776            if (_current.empty) _current = _original; 
    17771777        } 
    17781778 
    17791779        @property Cycle!(R) save() { 
     
    17981798    private alias typeof(R[0]) ElementType; 
    17991799    private ElementType* _ptr; 
    18001800    private size_t _index; 
    18011801 
    18021802    this(ref R input, size_t index = 0) 
    18031803    { 
    18041804        _ptr = input.ptr; 
    18051805        _index = index; 
    18061806    } 
    18071807    /// Range primitive implementations. 
    1808     ref ElementType front() 
     1808    @property ref ElementType front() 
    18091809    { 
    18101810        return _ptr[_index % R.length]; 
    18111811    } 
    18121812    /// Ditto 
    18131813    enum bool empty = false; 
    18141814    /// Ditto 
    18151815    void popFront() { ++_index; } 
    18161816    ref ElementType opIndex(size_t n) 
    18171817    { 
    18181818        return _ptr[(n + _index) % R.length]; 
     
    19711971            foreach (i, Unused; R) 
    19721972            { 
    19731973                result.ranges.field[i] = ranges.field[i].save; 
    19741974            } 
    19751975            return result; 
    19761976        } 
    19771977 
    19781978/** 
    19791979Returns a proxy for the current iterated element. 
    19801980 */ 
    1981     Proxy front() 
     1981    @property Proxy front() 
    19821982    { 
    19831983        Proxy result; 
    19841984        foreach (i, Unused; R) 
    19851985        { 
    19861986            result.ptrs.field[i] = &ranges.field[i].front; 
    19871987        } 
    19881988        return result; 
    19891989    } 
    19901990 
    19911991/** 
    19921992Returns a proxy for the rightmost element. 
    19931993 */ 
    1994     Proxy back() 
     1994    @property Proxy back() 
    19951995    { 
    19961996        Proxy result; 
    19971997        foreach (i, Unused; R) 
    19981998        { 
    19991999            result.ptrs.field[i] = &ranges.field[i].back; 
    20002000        } 
    20012001        return result; 
    20022002    } 
    20032003 
    20042004/** 
     
    22112211 
    22122212    this(StateType[stateSize] initial) { _state = initial; } 
    22132213 
    22142214    void popFront() 
    22152215    { 
    22162216        _state[_n % stateSize] = binaryFun!(fun, "a", "n")( 
    22172217            cycle(_state, _n), _n + stateSize); 
    22182218        ++_n; 
    22192219    } 
    22202220 
    2221     StateType front() 
     2221    @property StateType front() 
    22222222    { 
    22232223        return _state[_n % stateSize]; 
    22242224    } 
    22252225 
    22262226    enum bool empty = false; 
    22272227} 
    22282228 
    22292229/// Ditto 
    22302230Recurrence!(fun, CommonType!(State), State.length) 
    22312231recurrence(alias fun, State...)(State initial) 
     
    22812281    ElementType _cache; 
    22822282 
    22832283public: 
    22842284    this(State initial, size_t n = 0) 
    22852285    { 
    22862286        this._state = initial; 
    22872287        this._n = n; 
    22882288        this._cache = compute(this._state, this._n); 
    22892289    } 
    22902290 
    2291     ElementType front() 
     2291    @property ElementType front() 
    22922292    { 
    22932293        //return ElementType.init; 
    22942294        return this._cache; 
    22952295    } 
    22962296 
    22972297    ElementType moveFront() 
    22982298    { 
    22992299        return move(_cache); 
    23002300    } 
    23012301 
     
    26262626            foreach (e; _input) 
    26272627            { 
    26282628                enforce(e.length == commonLength); 
    26292629            } 
    26302630        } 
    26312631    } 
    26322632 
    26332633/** 
    26342634   Forward range primitives. 
    26352635*/ 
    2636     bool empty() 
     2636    @property bool empty() 
    26372637    { 
    26382638        return _input.empty; 
    26392639    } 
    26402640 
    26412641/// Ditto 
    2642     ref ElementType front() 
     2642    @property ref ElementType front() 
    26432643    { 
    26442644        assert(!empty); 
    26452645        return _input.front.front; 
    26462646    } 
    26472647 
    26482648/// Ditto 
    26492649    void popFront() 
    26502650    { 
    26512651        assert(!empty); 
    26522652        _input.popFront; 
    26532653        prime; 
    26542654    } 
    26552655 
    26562656    static if (isBidirectionalRange!RangeOfRanges) 
    26572657    { 
    26582658/** 
    26592659   Bidirectional primitives. They are offered if $(D 
    26602660isBidirectionalRange!RangeOfRanges). 
    26612661 */ 
    2662         ref ElementType back() 
     2662        @property ref ElementType back() 
    26632663        { 
    26642664            return _input.back.front; 
    26652665        } 
    26662666/// Ditto 
    26672667        void popBack() 
    26682668        { 
    26692669            assert(!empty); 
    26702670            _input.popBack; 
    26712671            prime; 
    26722672        } 
     
    27652765            foreach (e; _input) 
    27662766            { 
    27672767                enforce(e.length == commonLength); 
    27682768            } 
    27692769        } 
    27702770    } 
    27712771 
    27722772/** 
    27732773   Forward range primitives. 
    27742774*/ 
    2775     bool empty() 
     2775    @property bool empty() 
    27762776    { 
    27772777        return _input.empty; 
    27782778    } 
    27792779 
    27802780/// Ditto 
    2781     ref ElementType front() 
     2781    @property ref ElementType front() 
    27822782    { 
    27832783        assert(!empty); 
    27842784        return _input.front[_n]; 
    27852785    } 
    27862786 
    27872787/// Ditto 
    27882788    void popFront() 
    27892789    { 
    27902790        assert(!empty); 
    27912791        _input.popFront; 
    27922792        prime; 
    27932793    } 
    27942794 
    27952795    static if (isBidirectionalRange!RangeOfRanges) 
    27962796    { 
    27972797/** 
    27982798   Bidirectional primitives. They are offered if $(D 
    27992799isBidirectionalRange!RangeOfRanges). 
    28002800 */ 
    2801         ref ElementType back() 
     2801        @property ref ElementType back() 
    28022802        { 
    28032803            return _input.back[_n]; 
    28042804        } 
    28052805        void popBack() 
    28062806        { 
    28072807            assert(!empty); 
    28082808            _input.popBack; 
    28092809            prime; 
    28102810        } 
    28112811    } 
     
    28632863 
    28642864struct Transposed(RangeOfRanges) 
    28652865{ 
    28662866    alias typeof(map!"a.front"(RangeOfRanges.init)) ElementType; 
    28672867 
    28682868    this(RangeOfRanges input) 
    28692869    { 
    28702870        this._input = input; 
    28712871    } 
    28722872 
    2873     ElementType front() 
     2873    @property ElementType front() 
    28742874    { 
    28752875        return map!"a.front"(_input); 
    28762876    } 
    28772877 
    28782878    void popFront() 
    28792879    { 
    28802880        foreach (ref e; _input) 
    28812881        { 
    28822882            if (e.empty) continue; 
    28832883            e.popFront; 
    28842884        } 
    28852885    } 
    28862886 
    28872887    // ElementType opIndex(size_t n) 
    28882888    // { 
    28892889    //     return _input[n].front; 
    28902890    // } 
    28912891 
    2892     bool empty() 
     2892    @property bool empty() 
    28932893    { 
    28942894        foreach (e; _input) 
    28952895            if (!e.empty) return false; 
    28962896        return true; 
    28972897    } 
    28982898 
    28992899    @property Transposed save() 
    29002900    { 
    29012901        return Transposed(_input.save); 
    29022902    }