本文整理汇总了C++中iter::dropwhile方法的典型用法代码示例。如果您正苦于以下问题:C++ iter::dropwhile方法的具体用法?C++ iter::dropwhile怎么用?C++ iter::dropwhile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类iter
的用法示例。
在下文中一共展示了iter::dropwhile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
std::vector<int> ivec{1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4};
for (auto& i : dropwhile([] (int i) {return i < 5;}, ivec)) {
std::cout << i << '\n';
i = 69;
}
assert(ivec.at(0) == 1);
assert(ivec.at(4) == 69);
for (auto i : dropwhile([] (int i) {return i < 5;}, range(10))) {
std::cout << i << '\n';
}
for (auto i : dropwhile([] (int i) {return i < 5;},
{1, 2, 3, 4, 5, 6, 7, 8, 9})) {
std::cout << i << '\n';
}
for (auto i : dropwhile([] (int i) {return i < 5;},
std::vector<int>{1, 2, 3, 4, 5, 6, 7, 8, 9})) {
std::cout << i << '\n';
}
return 0;
}
示例2: v
#include "helpers.hpp"
#include <vector>
#include <string>
#include <iterator>
#include "catch.hpp"
using iter::dropwhile;
using Vec = const std::vector<int>;
TEST_CASE("dropwhile: skips initial elements", "[dropwhile]") {
Vec ns{1,2,3,4,5,6,7,8};
auto d = dropwhile([](int i){return i < 5; }, ns);
Vec v(std::begin(d), std::end(d));
Vec vc = {5,6,7,8};
REQUIRE( v == vc );
}
TEST_CASE("dropwhile: doesn't skip anything if it shouldn't", "[dropwhile]") {
Vec ns {3,4,5,6};
auto d = dropwhile([](int i){return i < 3; }, ns);
Vec v(std::begin(d), std::end(d));
Vec vc = {3,4,5,6};
REQUIRE( v == vc );
}
TEST_CASE("dropwhile: skips all elements when all are true under predicate",
"[dropwhile]") {