23 template <
class Chunkedseq,
class UnaryPredicate>
24 void pcopy_if(
typename Chunkedseq::iterator first,
25 typename Chunkedseq::iterator last,
26 Chunkedseq& destination,
27 const UnaryPredicate& pred) {
28 using iterator =
typename Chunkedseq::iterator;
30 using ptr =
typename Chunkedseq::const_pointer;
32 const long cutoff = 8192;
34 long sz = last.size() - first.size();
40 for (ptr p = lo; p < hi; p++) {
43 destination.push_back(v);
50 iterator mid = first + (sz/2);
52 Chunkedseq destination2;
56 pcopy_if(first, mid, destination, pred);
57 pcopy_if(mid, last, destination2, pred);
59 destination.concat(destination2);
63 int main(
int argc,
const char * argv[]) {
65 const int chunk_size = 2;
71 pcopy_if(mydeque.
begin(), mydeque.
end(), mydeque2, [] (
int i) {
return i%2==0; });
73 std::cout <<
"mydeque2 contains:";
74 auto p = mydeque2.
begin();
75 while (p != mydeque2.
end())
76 std::cout <<
" " << *p++;
77 std::cout << std::endl;
iterator begin() const
Returns iterator to beginning.
void pcopy_if(typename Chunkedseq::iterator first, typename Chunkedseq::iterator last, Chunkedseq &destination, const UnaryPredicate &pred)
[pcopy_if_example]
iterator end() const
Returns iterator to end.
int main(int argc, const char *argv[])
Chunked-sequence functor.