经过一番痛苦后,我设法将这个最小的 boost filter_iterator 示例拼凑在一起
using namespace std;
std::function<bool(uint32_t)> stlfunc= [](uint32_t n){return n%3==0;};
int main()
{
vector<uint32_t> numbers{11,22,33,44,55,66,77,3,6,9};
auto start = boost::make_filter_iterator(stlfunc, numbers.begin(), numbers.end());
auto end = boost::make_filter_iterator(stlfunc, numbers.end() , numbers.end());
auto elem = std::max_element(start,end);
cout << *elem;
}
它工作得很好,但我想知道为什么 make_filter_iterator 需要numbers.end()
?那样使用它可能是错误的,我从 C 数组示例中猜测它:http:
//www.boost.org/doc/libs/1_53_0/libs/iterator/example/filter_iterator_example.cpp