Пример #1
0
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
0
#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]") {