Skip to main content

StrongId Struct Template

A strongly-typed identifier using tag-based type safety. More...

Declaration

template <typename Tag> struct helios::core::types::StrongId<Tag> { ... }

Friends Index

template <typename Tag>
booloperator==

Equality comparison. More...

Public Constructors Index

template <typename Tag>
constexprStrongId (const std::string_view str) noexcept

Constructs from a compile-time string. More...

template <typename Tag>
constexprStrongId (const StrongId_t id) noexcept

Constructs from a raw underlying value. More...

template <typename Tag>
constexprStrongId (no_init_t)

Constructs an uninitialized ID. More...

template <typename Tag>
constexprStrongId ()

Default constructor creating an uninitialized ID. More...

Public Operators Index

template <typename Tag>
operator bool () const noexcept

Checks if the ID is valid (non-zero). More...

template <typename Tag>
constexpr booloperator< (const StrongId &other) const noexcept

Less-than comparison for ordering. More...

template <typename Tag>
constexpr booloperator> (const StrongId &other) const noexcept

Greater-than comparison for ordering. More...

Public Member Functions Index

template <typename Tag>
boolisValid () const noexcept

Returns true if the strong id is considered valid. More...

template <typename Tag>
StrongId_tvalue () const noexcept

Returns the underlying ID value. More...

Private Member Attributes Index

template <typename Tag>
StrongId_tid_ {}

The underlying ID value. More...

Description

A strongly-typed identifier using tag-based type safety.

Provides compile-time type safety for identifiers by associating each ID type with a unique tag struct. Supports compile-time string hashing via FNV-1a algorithm.

Template Parameters
Tag

Empty struct used to distinguish different ID types.

Definition at line 27 of file StrongId.ixx.

Friends

operator==

friend bool StrongId, StrongId
constexpr noexcept default

Equality comparison.

Definition at line 100 of file StrongId.ixx.

Reference helios::core::types::StrongId< Tag >::StrongId.

Public Constructors

StrongId()

template <typename Tag>
helios::core::types::StrongId< Tag >::StrongId (const std::string_view str)
inline explicit constexpr noexcept

Constructs from a compile-time string.

Uses FNV-1a hashing to convert the string to an ID.

Parameters
str

The string to hash.

Definition at line 45 of file StrongId.ixx.

45 explicit constexpr StrongId(const std::string_view str) noexcept
46 : StrongId(fnv1a_hash(str)) {}

Referenced by helios::core::types::StrongId< Tag >::operator<, helios::core::types::StrongId< Tag >::operator==, helios::core::types::StrongId< Tag >::operator> and helios::core::types::StrongId< Tag >::StrongId.

StrongId()

template <typename Tag>
helios::core::types::StrongId< Tag >::StrongId (const StrongId_t id)
inline explicit constexpr noexcept

Constructs from a raw underlying value.

Parameters
id

The raw ID value.

Definition at line 54 of file StrongId.ixx.

54 explicit constexpr StrongId(const StrongId_t id) noexcept
55 : id_(id) {
56 }

StrongId()

template <typename Tag>
helios::core::types::StrongId< Tag >::StrongId (no_init_t)
inline explicit constexpr

Constructs an uninitialized ID.

Parameters
<a href="/docs/helios/structs/helios/core/types/no-init-t">no_init_t</a>

Tag type indicating no initialization.

Definition at line 63 of file StrongId.ixx.

63 explicit constexpr StrongId(no_init_t) {};

StrongId()

template <typename Tag>
helios::core::types::StrongId< Tag >::StrongId ()
inline explicit constexpr

Default constructor creating an uninitialized ID.

Definition at line 68 of file StrongId.ixx.

68 explicit constexpr StrongId() : StrongId(no_init){};

References helios::core::types::no_init and helios::core::types::StrongId< Tag >::StrongId.

Public Operators

operator bool()

template <typename Tag>
helios::core::types::StrongId< Tag >::operator bool ()
inline explicit nodiscard noexcept

Checks if the ID is valid (non-zero).

Returns

True if the ID is non-zero.

Definition at line 93 of file StrongId.ixx.

93 [[nodiscard]] explicit operator bool() const noexcept {
94 return id_ != 0;
95 }

operator<()

template <typename Tag>
bool helios::core::types::StrongId< Tag >::operator< (const StrongId & other)
inline constexpr noexcept

Less-than comparison for ordering.

Parameters
other

The other ID to compare.

Returns

True if this ID is less than the other.

Definition at line 109 of file StrongId.ixx.

109 constexpr bool operator<(const StrongId& other) const noexcept {
110 return id_ < other.id_;
111 }

Reference helios::core::types::StrongId< Tag >::StrongId.

operator>()

template <typename Tag>
bool helios::core::types::StrongId< Tag >::operator> (const StrongId & other)
inline constexpr noexcept

Greater-than comparison for ordering.

Parameters
other

The other ID to compare.

Returns

True if this ID is greater than the other.

Definition at line 120 of file StrongId.ixx.

120 constexpr bool operator>(const StrongId& other) const noexcept {
121 return id_ > other.id_;
122 }

Reference helios::core::types::StrongId< Tag >::StrongId.

Public Member Functions

isValid()

template <typename Tag>
bool helios::core::types::StrongId< Tag >::isValid ()
inline nodiscard noexcept

Returns true if the strong id is considered valid.

Returns

True if the StrongId is considered valid, else false.

Definition at line 75 of file StrongId.ixx.

75 [[nodiscard]] bool isValid() const noexcept {;
76 return id_ != 0;
77 }

value()

template <typename Tag>
StrongId_t helios::core::types::StrongId< Tag >::value ()
inline nodiscard noexcept

Returns the underlying ID value.

Returns

The raw underlying value.

Definition at line 84 of file StrongId.ixx.

84 [[nodiscard]] StrongId_t value() const noexcept {
85 return id_;
86 }

Private Member Attributes

id_

template <typename Tag>
StrongId_t helios::core::types::StrongId< Tag >::id_ {}

The underlying ID value.

Definition at line 34 of file StrongId.ixx.

34 StrongId_t id_{};

The documentation for this struct was generated from the following file:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.