1

I am trying to get the difference between two ranges but have little luck. Something like

vector<int> l{ 1,5,6 };
auto diff = views::ints(1,10) - view::all( l );
==> Range<int> { 2,3,4,7,8,9 }

By the way. Are there any good writings on range-v3? Something to make me wiser?

Thanks.

4

1 回答 1

1

您正在寻找set_difference算法或其惰性view版本:

#include <range/v3/view/iota.hpp>
#include <range/v3/view/set_algorithm.hpp>
#include <iostream>
#include <vector>

int main() {
    std::vector<int> l{ 1,5,6 };
    auto diff = ranges::view::set_difference(ranges::view::ints(1,10), l);
    std::cout << diff << '\n'; // [2,3,4,7,8,9]
}
于 2017-03-13T21:29:20.930 回答