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

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


--- Comment #0 from Heromyth <bitwo...@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
{
    @property 
    {
        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);
        //m_Children.clear();        

        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);
    }

    this()
    {
    }
}


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

    return 0;
}

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

Reply via email to