ident.hpp 1018 B

1234567891011121314151617181920212223242526272829303132333435
  1. #ifndef ENTT_CORE_IDENT_HPP
  2. #define ENTT_CORE_IDENT_HPP
  3. #include <cstddef>
  4. #include <type_traits>
  5. #include <utility>
  6. #include "fwd.hpp"
  7. #include "type_traits.hpp"
  8. namespace entt {
  9. /**
  10. * @brief Type integral identifiers.
  11. * @tparam Type List of types for which to generate identifiers.
  12. */
  13. template<typename... Type>
  14. class ident {
  15. template<typename Curr, std::size_t... Index>
  16. [[nodiscard]] static constexpr id_type get(std::index_sequence<Index...>) noexcept {
  17. static_assert((std::is_same_v<Curr, Type> || ...), "Invalid type");
  18. return (0 + ... + (std::is_same_v<Curr, type_list_element_t<Index, type_list<std::decay_t<Type>...>>> ? id_type{Index} : id_type{}));
  19. }
  20. public:
  21. /*! @brief Unsigned integer type. */
  22. using value_type = id_type;
  23. /*! @brief Statically generated unique identifier for the given type. */
  24. template<typename Curr>
  25. static constexpr value_type value = get<std::decay_t<Curr>>(std::index_sequence_for<Type...>{});
  26. };
  27. } // namespace entt
  28. #endif