www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - What is put() useful for with regards to dynamic arrays?

reply Andrej Mitrovic <none none.none> writes:
import std.range;

void main()
{
    int[] a = [1, 2, 3];
    
    a.put(6);
    assert(a == [2, 3]);
    
    a.put([1, 2]);
    assert(a.length == 0);
}

Seems kind of odd.. put is implemented as an append method for some custom
types, e.g. std.array.appender. But for arrays put just removes Item or
RangeLength number of elements from the array. What's the use case for this?
Apr 29 2011
parent reply "Lars T. Kyllingstad" <public kyllingen.NOSPAMnet> writes:
On Sat, 30 Apr 2011 00:09:09 -0400, Andrej Mitrovic wrote:

 import std.range;
 
 void main()
 {
     int[] a = [1, 2, 3];
     
     a.put(6);
     assert(a == [2, 3]);
     
     a.put([1, 2]);
     assert(a.length == 0);
 }
 
 Seems kind of odd.. put is implemented as an append method for some
 custom types, e.g. std.array.appender. But for arrays put just removes
 Item or RangeLength number of elements from the array. What's the use
 case for this?
This should probably be in a FAQ somewhere. :) http://www.digitalmars.com/d/archives/digitalmars/D/ std.array.put_doesn_t_put_106871.html -Lars
May 02 2011
parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
Thanks, that post explained it. Obviously I wasn't the first and
likely won't be the last person to run into this. Maybe put's
documentation could make a note of this.
May 02 2011