本文整理汇总了C++中DynamicList::transfer方法的典型用法代码示例。如果您正苦于以下问题:C++ DynamicList::transfer方法的具体用法?C++ DynamicList::transfer怎么用?C++ DynamicList::transfer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DynamicList
的用法示例。
在下文中一共展示了DynamicList::transfer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
List<DynamicList<label, 1, 0> > ldl(2);
ldl[0](0) = 0;
ldl[0](2) = 2;
ldl[0](3) = 3;
ldl[0](1) = 1;
ldl[0].setCapacity(5); // increase allocated size
ldl[1].setCapacity(10); // increase allocated size
ldl[0].reserve(15); // should increase allocated size
ldl[1].reserve(5); // should not decrease allocated size
ldl[1](3) = 2; // allocates space and sets value
// this works without a segfault, but doesn't change the list size
ldl[0][4] = 4;
ldl[1] = 3;
Info<< "<ldl>" << ldl << "</ldl>" << nl << "sizes: ";
forAll(ldl, i)
{
Info<< " " << ldl[i].size() << "/" << ldl[i].capacity();
}
Info<< endl;
List<List<label> > ll(2);
ll[0].transfer(ldl[0]);
ll[1].transfer(ldl[1].shrink());
Info<< "<ldl>" << ldl << "</ldl>" << nl << "sizes: ";
forAll(ldl, i)
{
Info<< " " << ldl[i].size() << "/" << ldl[i].capacity();
}
Info<< endl;
Info<< "<ll>" << ll << "</ll>" << nl << endl;
// test the transfer between DynamicLists
DynamicList<label, 1, 0> dlA;
DynamicList<label, 1, 0> dlB;
for (label i = 0; i < 5; i++)
{
dlA.append(i);
}
dlA.setCapacity(10);
Info<< "<dlA>" << dlA << "</dlA>" << nl << "sizes: "
<< " " << dlA.size() << "/" << dlA.capacity() << endl;
dlB.transfer(dlA);
// provokes memory error if previous transfer did not maintain
// the correct allocated space
dlB[6] = 6;
Info<< "Transferred to dlB" << endl;
Info<< "<dlA>" << dlA << "</dlA>" << nl << "sizes: "
<< " " << dlA.size() << "/" << dlA.capacity() << endl;
Info<< "<dlB>" << dlB << "</dlB>" << nl << "sizes: "
<< " " << dlB.size() << "/" << dlB.capacity() << endl;
// try with a normal list:
List<label> lstA;
lstA.transfer(dlB);
Info<< "Transferred to normal list" << endl;
Info<< "<lstA>" << lstA << "</lstA>" << nl << "sizes: "
<< " " << lstA.size() << endl;
Info<< "<dlB>" << dlB << "</dlB>" << nl << "sizes: "
<< " " << dlB.size() << "/" << dlB.capacity() << endl;
// Copy back and append a few time
for (label i=0; i < 3; i++)
{
dlB.append(lstA);
}
Info<< "appended list a few times" << endl;
Info<< "<dlB>" << dlB << "</dlB>" << nl << "sizes: "
<< " " << dlB.size() << "/" << dlB.capacity() << endl;
// assign the list (should maintain allocated space)
dlB = lstA;
Info<< "assigned list" << endl;
Info<< "<dlB>" << dlB << "</dlB>" << nl << "sizes: "
<< " " << dlB.size() << "/" << dlB.capacity() << endl;
// Copy back and append a few time
for (label i=0; i < 3; i++)
{
dlB.append(lstA);
}
// check allocation granularity
//.........这里部分代码省略.........