C++ collect algorithm? -
Every now and then, I should run again on a subset of elements of a container, or just want to remove them and ignore them. rest. I'm ending using Is there any reason for this lacking of STLs collected algorithms (in Ruby's collection) (we only Copy_if that is not the same)? Or is there any reason to use it? A possible implementation can be: But a All the answers below are great. I wish I could mark them all I did not know about their size). They work on iterator ranges, and algorithm changes that are made only through an assignment through an assignment. Therefore, your proposed operation is completely out of the scope of the standard algorithm. There may be a large additional set of standard "container-operations", in which it includes one, but "STL philosophy" is running on Iterators. The non-sluggish operation you can propose is The lazy version can not be done by pluging standard components simultaneously - there is no clear to silence the "output" of an algorithm directly in "input" of another algorithm without intermediate storage. There is no way. This is why Boost offers such an interesting variety of itater, as well as range. I do not know why they were not included in C ++ 11, but C + 11 was that it was rather late, the proposals were removed due to lack of time, so The reason for this can be as simple "considering the current workload known, it was not considered sufficiently significant to offer it." Regarding your particular implementation, not all containers have boost :: range :: adapters :: filtered to create this lazy collection for I
(auto & amp; ; I: Container | Filtered (bidak)) {// .. Do Dot}
template & lt; Class Container, Class Preddate & gt; Collect Container (Container & amp; C; Kindle & amp; amp; amp; P) {Container N; (Auto & amp; amp; i: c) {for {((i)} {n.push_back (i); }} Return n; }
lazy_collect can also be useful to avoid duplication.
std :: back_inserter . Collecting stuff is as easy now:
Promotion: copy (original) filter (predicate), std :: back_inserter (archive)); Standard algorithms do not work directly on containers (making or destroying or changing them).
std :: back_inserter and
std :: copy_if (optionally using trick drivers) or Can be done using
move_if (if you roll it yourself).
std :: copy_if went missing from C ++ 03, but it was a casual inspection.
push_back , and therefore you probably will not use
container as template parameter name should do. Requirements of
pushback succession will be more descriptive.
Comments
Post a Comment