Created
October 20, 2016 09:15
-
-
Save SergNikitin/1666fc116124ed4139f587526f0158b2 to your computer and use it in GitHub Desktop.
Explicit ID
This file contains 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
template <typename T, typename UniqueTag> | |
class ExplicitArithmeticID | |
{ | |
public: | |
static_assert(std::is_arithmetic<T>::value, "ExplicitArithmeticID is for arithmetic types only"); | |
using UnderlyingType = T; | |
constexpr explicit ExplicitArithmeticID(T value) : mUnderlyingValue(value) {}; | |
const T& underlying() const | |
{ | |
return mUnderlyingValue; | |
} | |
private: | |
T mUnderlyingValue; | |
}; | |
struct GeoIDTag {}; | |
using GeoID = ExplicitArithmeticID<int, GeoIDTag>; | |
struct TerIDTag {}; | |
using TerID = ExplicitArithmeticID<int, TerIDTag>; | |
void foo(GeoID) {} | |
int main() | |
{ | |
foo(GeoID(0)); | |
// foo(TerID(0)); // compilation error | |
system("pause"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment