55 RAV_ASSERT(next_id_ != 0,
"Next ID is 0, which is reserved for invalid IDs");
56 RAV_ASSERT(next_id_ != std::numeric_limits<uint64_t>::max(),
"The next ID is at the maximum value");
57 return Id(next_id_.fetch_add(1));
70 std::atomic<uint64_t> next_id_ {1};
79 explicit Id(
const uint64_t int_id) : id_(int_id) {}
81 Id(
const Id& other) =
default;
84 Id(
Id&& other)
noexcept =
default;
97 [[nodiscard]] uint64_t
value()
const {
105 return std::to_string(id_);
113 return lhs.id_ == rhs.id_;
117 return !(lhs == rhs);
134static_assert(std::atomic<Id>::is_always_lock_free);
135static_assert(std::is_trivially_copyable_v<Id>);
#define RAV_ASSERT(condition, message)
Asserts condition to be true, otherwise:
Generator & operator=(const Generator &)=delete
Generator & operator=(Generator &&)=delete
Generator(Generator &&)=delete
Id next()
This function is thread safe and can be safely called from any thread at any time.
Generator(const Generator &)=delete
void reset()
Resets the ID generator to start at 1 again.
Id(Id &&other) noexcept=default
bool operator==(const uint64_t value) const
bool is_valid() const noexcept
friend bool operator!=(const Id &lhs, const Id &rhs)
Id & operator=(const Id &other)=default
Id(const Id &other)=default
Id & operator=(Id &&other) noexcept=default
static Id get_next_process_wide_unique_id() noexcept
Returns the next id from a process-wide, global generator.
Id(const uint64_t int_id)
Constructs an id from an integer value.
std::string to_string() const
friend bool operator==(const Id &lhs, const Id &rhs)