http://d.puremagic.com/issues/show_bug.cgi?id=6193


Steven Schveighoffer <schvei...@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
         AssignedTo|nob...@puremagic.com        |schvei...@yahoo.com
           Severity|enhancement                 |minor


--- Comment #1 from Steven Schveighoffer <schvei...@yahoo.com> 2011-06-22 
06:02:18 PDT ---
It is intentionally missing from Appender when the data type is immutable or
const.  See the code here:

https://github.com/D-Programming-Language/phobos/blob/master/std/array.d#L1870

The issue is because Appender owns the data it's appending to, clearing the
data will *reuse* the buffer to do appending again.  But this would violate the
requirements for immutable.  This is different from setting a slice length to
0, because a slice *does not own* the data.  Appending to a slice whose length
was set to 0 would allocate a *new* block to append into.

The equivalent slice code for Appender.clear is:

slice.length = 0;
slice.assumeSafeAppend();

There is a reason const is also included.  Appender can take an *existing*
buffer and use it as the base for appending.  Since Appender!(const(T)[]) can
accept an immutable(T)[], you would have the same issue if you then called
clear on the data.

I'll note that clear is not enabled when the Appender is for const or immutable
arrays in the documentation.

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

Reply via email to