Skip to content

Instantly share code, notes, and snippets.

@burritoOverflow
Created May 6, 2020 00:05
Show Gist options
  • Save burritoOverflow/3012a5d84515efff58661c4aba8d3687 to your computer and use it in GitHub Desktop.
Save burritoOverflow/3012a5d84515efff58661c4aba8d3687 to your computer and use it in GitHub Desktop.
#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