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


C++ StringList::keep_if_all方法代码示例

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


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

示例1: TestKeepIf

bool TestKeepIf() {
    BEGIN_TEST;
    StringList list;
    const char* original[] = {"",     "foo",   "bar",    "baz",    "qux",
                              "quux", "corge", "grault", "garply", "waldo",
                              "fred", "plugh", "xyzzy",  "thud",   ""};

    const char* expected1[] = {"bar", "corge", "grault", "garply", "plugh"};

    const char* expected2[] = {"corge", "grault", "garply", "plugh"};

    const char* expected3[] = {"garply"};

    for (size_t i = 0; i < arraysize(original); ++i) {
        list.push_back(original[i]);
    }

    // Null string has no effect
    list.keep_if(nullptr);
    EXPECT_TRUE(Match(&list, original, 0, arraysize(original)));

    // Empty string matches everything
    list.keep_if("");
    EXPECT_TRUE(Match(&list, original, 0, arraysize(original)));

    // Match a string
    list.keep_if("g");
    EXPECT_TRUE(Match(&list, expected2, 0, arraysize(expected2)));

    // Match a string that would have matched elements in the original list
    list.keep_if("ar");
    EXPECT_TRUE(Match(&list, expected3, 0, arraysize(expected3)));

    // Use a string that doesn't match anything
    list.keep_if("zzz");
    EXPECT_TRUE(list.is_empty());

    // Reset and apply both matches at once with logical-or
    StringList substrs;
    substrs.push_back("g");
    substrs.push_back("ar");

    list.clear();
    for (size_t i = 0; i < arraysize(original); ++i) {
        list.push_back(original[i]);
    }
    list.keep_if_any(&substrs);
    EXPECT_TRUE(Match(&list, expected1, 0, arraysize(expected1)));

    // Reset and apply both matches at once with logical-and
    list.clear();
    for (size_t i = 0; i < arraysize(original); ++i) {
        list.push_back(original[i]);
    }
    list.keep_if_all(&substrs);
    EXPECT_TRUE(Match(&list, expected3, 0, arraysize(expected3)));

    END_TEST;
}
开发者ID:saltstar,项目名称:smartnix,代码行数:59,代码来源:string-list.cpp


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