[Issue 3199] sort(chain(...)) doesn't work in some cases

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Aug 28 09:10:42 PDT 2009


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


Andrei Alexandrescu <andrei at metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED




--- Comment #2 from Andrei Alexandrescu <andrei at metalanguage.com>  2009-08-28 09:10:41 PDT ---
The first example creates three empty slices a, b, and c. Then abc is defined
as a slice of slices initialized with those empty slices. Subsequently abc is
filled but the initial slices a, b, and c remain empty. Therefore sort(chain(a,
b, c)) sorts an empty range so it is ineffectual.

The second example (after fixing) works indeed correctly because abc does not
undergo modifications independently from a, b, and c.

The third example is subtle. Assigning to the length of a slice, e.g.

t,length = uniform(8, 17);

may or may not spawn a new allocation (and therefore a divergence of what abc
holds versus what a, b, and c hold individually). Therefore, the behavior will
be erratic depending on what the random number generator yields.

Assigning to length in slices has always had that danger. We have recently
decided to prevent assignable length and defining a separate array type that
has modifiable length.

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


More information about the Digitalmars-d-bugs mailing list