family.hpp 827 B

1234567891011121314151617181920212223242526272829303132
  1. #ifndef ENTT_CORE_FAMILY_HPP
  2. #define ENTT_CORE_FAMILY_HPP
  3. #include "../config/config.h"
  4. #include "fwd.hpp"
  5. namespace entt {
  6. /**
  7. * @brief Dynamic identifier generator.
  8. *
  9. * Utility class template that can be used to assign unique identifiers to types
  10. * at runtime. Use different specializations to create separate sets of
  11. * identifiers.
  12. */
  13. template<typename...>
  14. class family {
  15. inline static ENTT_MAYBE_ATOMIC(id_type) identifier{};
  16. public:
  17. /*! @brief Unsigned integer type. */
  18. using value_type = id_type;
  19. /*! @brief Statically generated unique identifier for the given type. */
  20. template<typename... Type>
  21. // at the time I'm writing, clang crashes during compilation if auto is used instead of family_type
  22. inline static const value_type value = identifier++;
  23. };
  24. } // namespace entt
  25. #endif