nyarlathotep108 nyarlathotep108 - 1 year ago 56
C++ Question

How to (re)move from a container if predicate is satisfied?

How can I move the element into

using STL algorithm module?

std::remove_copy_if( list.begin( ), list.end( ), std::back_inserter( aux_list ),
[]( const value_type& item_ptr )
return !item_ptr->is_valid( );
} );

Answer Source

Use move iterators:

    [](const value_type& item_ptr) { return !item_ptr->valid(); });

Note that the elements still all exist in list - they weren't actually removed (this is a weirdly named algorithm - think of it as copy_unless()). So now you will have a bunch of elements in an unspecified state.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download