www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3861] New: std.array.put doesn't put--it takes.

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3861

           Summary: std.array.put doesn't put--it takes.
           Product: D
           Version: 2.030
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: major
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: paul.d.anderson comcast.net


--- Comment #0 from Paul D. Anderson <paul.d.anderson comcast.net> 2010-02-27
16:52:12 PST ---
From the description of the put primitive in std.range:

"r.put(e) puts e in the range (in a range-dependent manner) and advances to the
popFront position in the range. Successive calls to r.put add elements to the
range. put may throw to signal failure."

From the example of std.array for the put function:

void main()
{
    int[] a = [ 1, 2, 3 ];
    int[] b = a;
    a.put(5);
    assert(a == [ 2, 3 ]);
    assert(b == [ 5, 2, 3 ]);
}

So, "putting" 5 into the array a removes the first element in a, and changes
the value of the first element of b. I would expect the first assert in the
code above to read:

    assert(a == [ 5, 1, 2, 3 ]);

The implementation of std.array.put doesn't make sense: 

void put(T, E)(ref T[] a, E e) { assert(a.length); a[0] = e; a = a[1 .. $]; }

It modifies a[0] and then replaces the array with the tail of the array,
omitting the first element.

It's possible there is some arcane meaning to the word "put" that I'm not aware
of, but if it means "insert an element at the front of the range" then
std.array.put is wrongly implemented.

Paul

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 27 2010
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3861


Paul D. Anderson <paul.d.anderson comcast.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


--- Comment #1 from Paul D. Anderson <paul.d.anderson comcast.net> 2010-03-02
17:23:21 PST ---
It has been brought to my attention that the indicated behavior is correct. It
was an arcane meaning of the word "put". That's what I get for thinking in
English and not D.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 02 2010