Skip to content

Instantly share code, notes, and snippets.

@adiog
Created November 8, 2017 03:12
Show Gist options
  • Save adiog/9345048026827f66807655b1f20e43b4 to your computer and use it in GitHub Desktop.
Save adiog/9345048026827f66807655b1f20e43b4 to your computer and use it in GitHub Desktop.
copy-based-history
#include <cassert>
template <typename T>
using history_t = std::vector<T>;
template <typename T>
void commit(history_t<T>& h) { assert(h.size()); h.push_back(h.back()); }
template <typename T>
void undo(history_t<T>& h) { assert(h.size()); h.pop_back(); }
template <typename T>
T& current(history_t<T>& h) { assert(h.size()); return h.back();}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment