Skip to content

Instantly share code, notes, and snippets.

@tomwhoiscontrary
Created April 26, 2018 12:59
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 tomwhoiscontrary/bcd8ffb161e4cf51cc16f5d4c1b5bdd7 to your computer and use it in GitHub Desktop.
Save tomwhoiscontrary/bcd8ffb161e4cf51cc16f5d4c1b5bdd7 to your computer and use it in GitHub Desktop.
#include <iostream>
// modified from https://wandbox.org/permlink/YnHKdrHmMFiJsjOm
template <typename T, typename Deleter>
struct handle {
handle(T value, Deleter deleter = Deleter()) : value_(value), deleter_(deleter) {
}
~handle() {
deleter_.close(value_);
}
private:
T value_;
Deleter deleter_;
};
struct close_type {
static void close(int value) {
std::cout << value << std::endl;
}
};
int main() {
handle<int, close_type> h(3);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment