sandbox
Loading...
Searching...
No Matches
type_id.hpp
1#ifndef LIBSBX_UTILTY_TYPE_ID_HPP_
2#define LIBSBX_UTILTY_TYPE_ID_HPP_
3
4#include <cstdint>
5#include <type_traits>
6
7namespace sbx::utility {
8
9namespace detail {
10
11struct id_generator final {
12 [[nodiscard]] static auto next() noexcept -> std::uint32_t {
13 static auto id = std::uint32_t{};
14 return id++;
15 }
16}; // struct type_index
17
18} // namespace detail
19
20template<typename Type>
21struct type_id {
22
23 [[nodiscard]] static auto value() noexcept -> std::uint32_t {
24 static const auto value = detail::id_generator::next();
25 return value;
26 }
27
28 [[nodiscard]] constexpr operator std::uint32_t() const noexcept {
29 return value();
30 }
31
32}; // struct type_id
33
34} // namespace sbx::utility
35
36#endif // LIBSBX_UTILTY_TYPE_ID_HPP_
Definition: type_id.hpp:11
Definition: type_id.hpp:21