Logo

Programming-Idioms

History of Idiom 135 > diff from v31 to v32

Edit summary for version 32 by chardan:
[Cpp] It looks like the other examples didn't also show declaring the list itself.

Version 31

2019-09-27, 20:57:53

Version 32

2019-09-27, 20:59:38

Idiom #135 Remove item from list, by its value

Remove at most 1 item from list items, having value x.
This will alter the original list or return a new list, depending on which is more idiomatic. If there are several occurrences of x in items, remove only one of them.

Idiom #135 Remove item from list, by its value

Remove at most 1 item from list items, having value x.
This will alter the original list or return a new list, depending on which is more idiomatic. If there are several occurrences of x in items, remove only one of them.

Code
 list xs { "hello", "there", "world", "Mars" };

 erase(xs, "Mars");
Code
erase(xs, "Mars");
Comments bubble
C++20
Comments bubble
C++20; xs is std::list<>
Demo URL
https://godbolt.org/z/jzthR6
Demo URL
https://godbolt.org/z/jzthR6