在特定条件下跳过std :: for_each中的迭代

Dar*_*row 9 c++

我正在开发一个需要迭代一定范围的程序。我想知道是否可以continue在基于范围的for循环中使用时使用。

工作方式:

std::vector<std::string> v = {"foo", "bar", "baz", "foobar"};
for (auto s : v)
{
    if (*s.front() == 'b')
        continue;
    std::cout << s << std::endl;
}
Run Code Online (Sandbox Code Playgroud)

不工作:

std::vector<std::string> v = {"foo", "bar", "baz", "foobar"};
std::for_each(v.begin(), v.end(), [](const std::string& s) {
    if (*s.front() == 'b')
        continue;
    std::cout << s << std::endl;
});
Run Code Online (Sandbox Code Playgroud)

bip*_*pll 13

替换continuereturn