Skip to content

Instantly share code, notes, and snippets.

@sergeant-wizard
Created March 13, 2015 03:57
Show Gist options
  • Save sergeant-wizard/7eac340d5ca857d0ec3e to your computer and use it in GitHub Desktop.
Save sergeant-wizard/7eac340d5ca857d0ec3e to your computer and use it in GitHub Desktop.
strongly typed id
#include <iostream>
#include <stdint.h>
class Area;
class Quest;
template <typename T, typename Meaning>
struct Explicit
{
Explicit() {}
Explicit(T value) : value(value) {}
inline operator T () const { return value; }
T value;
};
using AreaId = Explicit<uint16_t, Area>;
using QuestId = Explicit<uint16_t, Quest>;
int main() {
AreaId areaId = 3;
AreaId areaId2 = 5;
QuestId questId = 4;
areaId2 = areaId;
// areaId2 = questId; // error
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment