www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7696] New: The Array container works improperly when using as a property


           Summary: The Array container works improperly when using as a
           Product: D
           Version: D2
          Platform: All
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: bitworld qq.com

--- Comment #0 from Heromyth <bitworld qq.com> 2012-03-12 22:46:16 PDT ---
When an array container using as a property, the inner array (m_Children) must
be set the capacity to a non-zero value. Otherwise, many operations (like
reserve, insertBack, etc.) on the outter array (Children) works improperly.

The sample code is below.
public class TestClass
        public Array!(int) Children() { return m_Children; }
        public void Children(Array!(int) value) { m_Children = value;}
    private Array!(int) m_Children;

    void populate()
        m_Children.reserve(0);    // the capacity can't be zero;
        //Children.reserve(10); // no effect
        writefln("%d", m_Children.capacity);
        writefln("%d", Children.capacity);

        for(int i=0; i< 5; i++)
            Children.insertBack(i);        // Here is the problem. It is
affected by m_Children's capacity. 
            //m_Children.insertBack(i); // ok
        writefln("Children length %d", Children.length);


int main(string[] args)
    TestClass testInstance = new TestClass();

    return 0;

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