Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dangelog opened this issue Sep 8, 2022 · 0 comments
Open

Comments

@dangelog
Copy link

dangelog commented Sep 8, 2022

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant