Template Class templated_id_t

Class Documentation

template<class derived_id_t, typename T>
class templated_id_t

Generic CRTP ID wrapper for strong typing and utilities.

This template wraps an integer ID type and provides typed arithmetic, comparisons, and helpers while preserving the derived ID type.

Template Parameters:
  • derived_id_t – Strongly typed ID class (e.g., frame_id_t).

  • T – Underlying integer type (e.g., uint32_t).

Public Functions

inline templated_id_t()

Default constructor initializing to UNSET.

templated_id_t(const templated_id_t&) = default

Copy constructor.

templated_id_t(templated_id_t&&) noexcept = default

Move constructor.

templated_id_t &operator=(const templated_id_t&) = default

Copy assignment.

templated_id_t &operator=(templated_id_t&&) noexcept = default

Move assignment.

inline templated_id_t(T id_)

Constructor from a given ID value

Parameters:

id_ – Raw numeric identifier stored by this wrapper.

inline T key() const

Get the underlying ID value

Returns:

Raw numeric value represented by this typed ID.

inline T operator()() const

Function call operator returns the key value

Returns:

Raw numeric value represented by this typed ID.

inline derived_id_t *operator->()

Arrow operator for pointer-like behavior (returns derived_id_t*)

inline const derived_id_t *operator->() const
inline derived_id_t &operator=(std::nullptr_t nullptr_)

Assignment from nullptr sets to UNSET

Parameters:

nullptr_ – Null token used to reset this ID to UNSET.

Returns:

Reference to this ID after reset.

inline derived_id_t operator+(T v_) const

Simple add operator (derived_id_t + raw)

Parameters:

v_ – Raw numeric offset added to this ID.

Returns:

New typed ID with value key() + v_.

inline derived_id_t operator-(T v_) const

Simple subtract operator (derived_id_t - raw)

Parameters:

v_ – Raw numeric offset subtracted from this ID.

Returns:

New typed ID with value key() - v_.

inline derived_id_t operator+(const derived_id_t &other_) const

Simple add operator (derived_id_t + derived_id_t)

Parameters:

other_ – Typed ID whose raw value is added to this ID.

Returns:

New typed ID with value key() + other_.key().

inline derived_id_t operator-(const derived_id_t &other_) const

Simple subtract operator (derived_id_t - derived_id_t)

Parameters:

other_ – Typed ID whose raw value is subtracted from this ID.

Returns:

New typed ID with value key() - other_.key().

inline derived_id_t operator++()

Prefix increment operator

Returns:

This ID after incrementing its raw value.

inline derived_id_t operator++(int int_)

Postfix increment operator

Parameters:

int_ – Dummy integer used to select postfix increment syntax.

Returns:

Copy of the ID value before incrementing.

inline bool operator==(const derived_id_t &other_) const

Equality comparison

Parameters:

other_ – Typed ID compared against this instance.

Returns:

true when both IDs store the same raw value.

inline bool operator==(const T other_) const

Equality comparison with raw ID value

Parameters:

other_ – Raw numeric value compared against this ID.

Returns:

true when key() equals other_.

inline bool operator!=(const derived_id_t &other_) const

Inequality comparison

Parameters:

other_ – Typed ID compared against this instance.

Returns:

true when raw values differ.

inline bool operator!=(const T other_) const

Inequality comparison with raw ID value

Parameters:

other_ – Raw numeric value compared against this ID.

Returns:

true when key() differs from other_.

inline bool operator<(const derived_id_t &other_) const

Less-than comparison

Parameters:

other_ – Typed ID compared against this instance.

Returns:

true when this ID raw value is smaller.

inline bool operator<(const T other_) const

Less-than comparison with raw ID value

Parameters:

other_ – Raw numeric value compared against this ID.

Returns:

true when key() is smaller than other_.

inline bool operator>(const derived_id_t &other_) const

Greater-than comparison

Parameters:

other_ – Typed ID compared against this instance.

Returns:

true when this ID raw value is greater.

inline bool operator>(const T other_) const

Greater-than comparison with raw ID value

Parameters:

other_ – Raw numeric value compared against this ID.

Returns:

true when key() is greater than other_.

inline bool operator<=(const derived_id_t &other_) const

Less-than-or-equal comparison

Parameters:

other_ – Typed ID compared against this instance.

Returns:

true when this ID raw value is less or equal.

inline bool operator<=(const T other_) const

Less-than-or-equal comparison with raw ID value

Parameters:

other_ – Raw numeric value compared against this ID.

Returns:

true when key() is less than or equal to other_.

inline bool operator>=(const derived_id_t &other_) const

Greater-than-or-equal comparison

Parameters:

other_ – Typed ID compared against this instance.

Returns:

true when this ID raw value is greater or equal.

inline bool operator>=(const T other_) const

Greater-than-or-equal comparison with raw ID value

Parameters:

other_ – Raw numeric value compared against this ID.

Returns:

true when key() is greater than or equal to other_.

inline std::string to_string() const

to string

Returns:

"UNSET" for unset IDs, otherwise the numeric ID as text.

inline void print(std::string prefix_ = "") const

Print function

Parameters:

prefix_ – Prefix prepended to the printed ID line.

inline operator std::string() const

Conversion operator to std::string

Returns:

String representation of this typed ID.

Public Static Attributes

static constexpr T UNSET = std::numeric_limits<T>::max()

Sentinel value used to represent an unset identifier. It marks IDs that have not been assigned yet.

Protected Functions

inline derived_id_t &derived()

Returns this object cast to the CRTP-derived type.

Returns:

Reference to this object cast as derived_id_t.

inline const derived_id_t &derived() const

Returns this object cast to the const CRTP-derived type.

Returns:

Const reference to this object cast as derived_id_t.

Private Members

T _key

Friends

inline friend std::ostream &operator<<(std::ostream &os_, const derived_id_t &id_)

Stream operator (prints derived_id_t)

Parameters:
  • os_ – Output stream receiving the formatted ID.

  • id_ – ID value written to os_.

Returns:

Reference to os_ for stream chaining.