Skip to content

Instantly share code, notes, and snippets.

@qrealka
Last active June 13, 2019 11:44
Show Gist options
  • Save qrealka/9ffbe8ec4d047f4f4ee3ae6b72c1df3b to your computer and use it in GitHub Desktop.
Save qrealka/9ffbe8ec4d047f4f4ee3ae6b72c1df3b to your computer and use it in GitHub Desktop.
Badge pattern
template<typename T>
class Badge {
friend T;
Badge() {}
};
class Device;
class VFS {
public:
static VFS& the() { static VFS instance; return instance; }
void register_device(Device&, Badge<Device>) {}
void unregister_device(Device&, Badge<Device>){}
};
class Device {
public:
Device()
{
VFS::the().register_device(*this, {});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment