当前位置: 首页>>代码示例>>C++>>正文


C++ DynamicList::xfer方法代码示例

本文整理汇总了C++中DynamicList::xfer方法的典型用法代码示例。如果您正苦于以下问题:C++ DynamicList::xfer方法的具体用法?C++ DynamicList::xfer怎么用?C++ DynamicList::xfer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DynamicList的用法示例。


在下文中一共展示了DynamicList::xfer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main


//.........这里部分代码省略.........
    // 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
    DynamicList<label, 6, 0> dlC;

    Info<< "<dlC>" << dlC << "</dlC>" << nl << "sizes: "
        << " " << dlC.size() << "/" << dlC.capacity() << endl;

    dlC.reserve(dlB.size());
    dlC = dlB;

    Info<< "<dlC>" << dlC << "</dlC>" << nl << "sizes: "
        << " " << dlC.size() << "/" << dlC.capacity() << endl;

    List<label> lstB(dlC.xfer());

    Info<< "Transferred to normal list via the xfer() method" << endl;
    Info<< "<lstB>" << lstB << "</lstB>" << nl << "sizes: "
        << " " << lstB.size() << endl;
    Info<< "<dlC>" << dlC << "</dlC>" << nl << "sizes: "
        << " " << dlC.size() << "/" << dlC.capacity() << endl;

    DynamicList<label> dlD(lstB.xfer());

    Info<< "Transfer construct from normal list" << endl;
    Info<< "<lstB>" << lstB << "</lstB>" << nl << "sizes: "
        << " " << lstB.size() << endl;
    Info<< "<dlD>" << dlD << "</dlD>" << nl << "sizes: "
        << " " << dlD.size() << "/" << dlD.capacity() << endl;

    DynamicList<label,10> dlE1(10);
    DynamicList<label> dlE2(dlE1);   // construct dissimilar

    Info<< "<dlE1>" << dlE1 << "</dlE1>" << nl << "sizes: "
        << " " << dlE1.size() << "/" << dlE1.capacity() << endl;
    Info<< "<dlE2>" << dlE2 << "</dlE2>" << nl << "sizes: "
        << " " << dlE2.size() << "/" << dlE2.capacity() << endl;

    for (label elemI=0; elemI < 5; ++elemI)
    {
        dlE1.append(4 - elemI);
        dlE2.append(elemI);
    }

    Info<< "<dlE2>" << dlE2 << "</dlE2>" << endl;

    DynamicList<label> dlE3(dlE2);   // construct identical
    Info<< "<dlE3>" << dlE3 << "</dlE3>" << endl;

    dlE3 = dlE1;   // assign dissimilar
    Info<< "<dlE3>" << dlE3 << "</dlE3>" << endl;

    dlE3 = dlE2;   // assign identical
    Info<< "<dlE3>" << dlE3 << "</dlE3>" << endl;


    Info<< "\nEnd\n";

    return 0;
}
开发者ID:themiwi,项目名称:freefoam-debian,代码行数:101,代码来源:DynamicListTest.C


注:本文中的DynamicList::xfer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。