Template class implementation of a Named Strong Id (a Strong Type with an underlying unsigned integer type (uint32_t)).
More...
|
|
using | ValueType = uint32_t |
| |
|
|
| StrongId (size_t value) |
| | Construct from size_t.
|
| |
|
| StrongId (int value) |
| | Construct from int.
|
| |
|
StrongId | Next () const |
| | An id following this one. Incremented by 1.
|
| |
|
std::string | ToString () const |
| | Convert the id to string.
|
| |
|
| StrongType (uint32_t value) |
| |
|
std::enable_if_t< std::is_arithmetic_v< RT >, RT > | As () const |
| | Cast to a specified type. Only work for arithmetic types.
|
| |
|
bool | operator== (const StrongType &other) const |
| |
|
bool | operator!= (const StrongType &other) const |
| |
|
bool | operator< (const StrongType &other) const |
| |
|
bool | operator> (const StrongType &other) const |
| |
|
const uint32_t & | operator* () const |
| | Get underlying value using the * operator.
|
| |
|
|
static std::vector< StrongId< PhantomType > > | CreateIds (const std::vector< unsigned > &ids) |
| | Creates vector of specific strong ids values from the vector of unsigned values.
|
| |
|
|
uint32_t | value_ |
| | The actual underlying value.
|
| |
template<typename PhantomType>
struct utils::StrongId< PhantomType >
Template class implementation of a Named Strong Id (a Strong Type with an underlying unsigned integer type (uint32_t)).
- Note
- https://www.fluentcpp.com/2016/12/08/strong-types-for-strong-interfaces/ Strong Id is an integral type (uint32_t) specific for the given usage (usually as an id of a class). It prevents implicit conversions to and from other types, as well as comparisons to other types.
- Template Parameters
-
| PhantomType | An unused type specific for each Strong Type to ensure the Strong Type is different from every other type. |