[Issue 7696] New: The Array container works improperly when using as a property
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Mar 12 22:46:07 PDT 2012
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: nobody at puremagic.com
ReportedBy: bitworld at qq.com
--- Comment #0 from Heromyth <bitworld at 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: -------
More information about the Digitalmars-d-bugs
mailing list