Skip to content

In remove / remove_if consider C++20's uniform erasure protocol #8

@dangelog

Description

@dangelog

If you have a std::list, you're supposed to call list.remove_if(predicate), and not std::remove_if(list, predicate).

That's because shuffling around the nodes of the list can be much much cheaper than shuffling around the contents of those nodes.

To cope with these differences, C++20 introduced free erase and erase_if functions, which I have also added to Qt containers.

remove/remove_if (or erase, cf #7 ) should therefore have some dispatching logic inside:

  • if you can call (through ADL!) erase(container, ...) or erase_if(container, ...) then do that
  • otherwise do the erase/remove idiom

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions