0

How can I move the element into aux_list 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( );
                     } );
nyarlathotep108
  • 5,275
  • 2
  • 26
  • 64

1 Answers1

1

Use move iterators:

std::remove_copy_if(
    std::make_move_iterator(list.begin()),
    std::make_move_iterator(list.end()),
    std::back_inserter(aux_list),
    [](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.

Barry
  • 286,269
  • 29
  • 621
  • 977