Skip to content

Instantly share code, notes, and snippets.

@Trass3r
Created July 10, 2020 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Trass3r/93ece025888135710a267ee10afb696c to your computer and use it in GitHub Desktop.
Save Trass3r/93ece025888135710a267ee10afb696c to your computer and use it in GitHub Desktop.
useful algorithms
template <typename Container>
static void moveElementToFront(Container& c, const typename Container::value_type& e)
{
auto it = std::find(c.begin(), c.end(), e);
if (it != c.end())
std::rotate(c.begin(), it, it + 1);
}
// TODO: multi-element version and non-contiguous version using std::partition
template <typename Container>
static void moveElementToBack(Container& c, const typename Container::value_type& e)
{
auto it = std::find(c.begin(), c.end(), e);
if (it != c.end())
std::rotate(it, it + 1, c.end());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment