sandbox
Loading...
Searching...
No Matches
type_id.hpp
1#ifndef LIBSBX_UTILITY_TYPE_ID_HPP_
2#define LIBSBX_UTILITY_TYPE_ID_HPP_
3
4#include <cstdint>
5#include <type_traits>
6
7namespace sbx::utility {
8
9namespace detail {
10
11template<typename Scope>
12struct id_generator final {
13 [[nodiscard]] static auto next() noexcept -> std::uint32_t {
14 static auto id = std::uint32_t{};
15 return id++;
16 }
17}; // struct id_generator
18
20
21} // namespace detail
22
29template<typename Scope, typename Type>
31
32 using type = Type;
33 using scope = Scope;
34
40 [[nodiscard]] static auto value() noexcept -> std::uint32_t {
41 static const auto value = detail::id_generator<Scope>::next();
42
43 return value;
44 }
45
46 [[nodiscard]] constexpr operator std::uint32_t() const noexcept {
47 return value();
48 }
49
50}; // struct type_id
51
57template<typename Type>
58using type_id = scoped_type_id<detail::default_type_id_scope, Type>;
59
60} // namespace sbx::utility
61
62#endif // LIBSBX_UTILITY_TYPE_ID_HPP_
Definition: type_id.hpp:12
A scoped type ID generator. Allows for generating unique IDs for types within a specific scope.
Definition: type_id.hpp:30
static auto value() noexcept -> std::uint32_t
Generates a unique ID for the type.
Definition: type_id.hpp:40