Created
March 13, 2015 03:57
-
-
Save sergeant-wizard/7eac340d5ca857d0ec3e to your computer and use it in GitHub Desktop.
strongly typed id
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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