Outpost Universe Forums

Off Topic => Computers & Programming General => Topic started by: Hooman on November 28, 2019, 04:27:27 PM

Title: C++ Uniform Container Erasure
Post by: Hooman on November 28, 2019, 04:27:27 PM
I was watching some programming videos and found this one:
C++20's Uniform Container Erasure (https://www.youtube.com/watch?v=YGAX509TCQs)

It seems C++ is finally getting an easy way to remove items from containers. For example, to remove all occurrences of a value from a vector:
Code: [Select]
erase(vec, value);

This is in contrast to the older and much more verbose way:
Code: [Select]
vec.erase(std::remove(vec.begin(), vec.end(), value), vec.end());

The paper about it is here:
Uniform Container Erasure (https://isocpp.org/files/papers/n4009.txt)

Some documentation can be found at:
C++ standard libraries extensions, version 2 (https://en.cppreference.com/w/cpp/experimental/lib_extensions_2)

You'll notice the documentation links to specific methods for each of the container types, including std::string which isn't always thought of as a container.