Created
May 6, 2020 00:05
-
-
Save burritoOverflow/3012a5d84515efff58661c4aba8d3687 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <list> | |
#include <algorithm> | |
#include <iostream> | |
using namespace std; | |
template <class T> | |
typename list<T>::iterator _erase(list<T> &l, const T &val) | |
{ | |
auto it = find(l.begin(), l.end(), val); | |
if (it == l.end()) | |
return it; | |
l.erase(it); | |
return ++it; | |
} | |
int main() | |
{ | |
list<int> l{12, 41, 41, 76, 90}; | |
auto it = _erase(l, 12); | |
copy(l.begin(), l.end(), ostream_iterator<int>(cout, ", ")); | |
cout << '\n'; | |
std::cout << *it; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment