Skip to content

Instantly share code, notes, and snippets.

@bagobor
Created June 14, 2015 00:07
Show Gist options
  • Save bagobor/d4b2bc1384cea95ed52a to your computer and use it in GitHub Desktop.
Save bagobor/d4b2bc1384cea95ed52a to your computer and use it in GitHub Desktop.
Value/ID Handle class C++11 way
#include <algorithm>
#include <utility>
#include <iostream>
#include <memory>
struct Handle {
Handle (int val) : m_handl((int*)(void*)val, EmptyDeleter) { }
Handle(Handle&& src) : m_handl(std::move(src.m_handl)) {}
Handle(const Handle& that) = delete;
~Handle() = default;
static void EmptyDeleter(int*) {}
std::unique_ptr<int, void(*)(int *)> m_handl;
int get_value() { return (int)(void*)m_handl.get(); }
};
Handle foo() {
Handle h{ 51 };
return h;
}
int _tmain(int argc, _TCHAR* argv[])
{
Handle orig(5);
Handle copy = foo();// orig;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment