#pragma once #include namespace pangolin { template class Registration { public: using UnregisterFunc = std::function; Registration() : token() { } Registration(TokenType token, UnregisterFunc unregister) : token(token), unregister(unregister) { } // No copy constructor Registration(const Registration&) = delete; // Default move constructor Registration(Registration&& o) { *this = std::move(o); } Registration& operator =(Registration&& o) { token = o.token; unregister = std::move(o.unregister); o.unregister = nullptr; return *this; } ~Registration() { Release(); } void Release() { if(unregister) { unregister(token); token = TokenType(); } } const TokenType& Token() { return token; } private: TokenType token; UnregisterFunc unregister; }; }