Skip to content

Commit

Permalink
entity: make entt_traits sfinae-friendly and avoid using std::underly…
Browse files Browse the repository at this point in the history
…ing_type_t to define the entity traits types
  • Loading branch information
skypjack committed Jul 1, 2020
1 parent 902658f commit 371b541
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
14 changes: 12 additions & 2 deletions src/entt/entity/entity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,20 @@ namespace entt {
* Primary template isn't defined on purpose. All the specializations give a
* compile-time error unless the template parameter is an accepted entity type.
*/
template<typename>
template<typename, typename = void>
struct entt_traits;


/**
* @brief Entity traits for enumeration types.
* @tparam Type The type to check.
*/
template<typename Type>
struct entt_traits<Type, std::enable_if_t<std::is_enum_v<Type>>>
: entt_traits<std::underlying_type_t<Type>>
{};


/**
* @brief Entity traits for a 16 bits entity identifier.
*
Expand Down Expand Up @@ -111,7 +121,7 @@ namespace internal {

class null {
template<typename Entity>
using traits_type = entt_traits<std::underlying_type_t<Entity>>;
using traits_type = entt_traits<Entity>;

public:
template<typename Entity>
Expand Down
2 changes: 1 addition & 1 deletion src/entt/entity/registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace entt {
*/
template<typename Entity>
class basic_registry {
using traits_type = entt_traits<std::underlying_type_t<Entity>>;
using traits_type = entt_traits<Entity>;

template<typename Component>
struct pool_handler final: storage<Entity, Component> {
Expand Down
6 changes: 3 additions & 3 deletions src/entt/entity/snapshot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class basic_snapshot {
/*! @brief A registry is allowed to create snapshots. */
friend class basic_registry<Entity>;

using traits_type = entt_traits<std::underlying_type_t<Entity>>;
using traits_type = entt_traits<Entity>;

template<typename Component, typename Archive, typename It>
void get(Archive &archive, std::size_t sz, It first, It last) const {
Expand Down Expand Up @@ -164,7 +164,7 @@ class basic_snapshot_loader {
/*! @brief A registry is allowed to create snapshot loaders. */
friend class basic_registry<Entity>;

using traits_type = entt_traits<std::underlying_type_t<Entity>>;
using traits_type = entt_traits<Entity>;

template<typename Type, typename Archive>
void assign(Archive &archive) const {
Expand Down Expand Up @@ -299,7 +299,7 @@ class basic_snapshot_loader {
*/
template<typename Entity>
class basic_continuous_loader {
using traits_type = entt_traits<std::underlying_type_t<Entity>>;
using traits_type = entt_traits<Entity>;

void destroy(Entity entt) {
const auto it = remloc.find(entt);
Expand Down
2 changes: 1 addition & 1 deletion src/entt/entity/sparse_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class sparse_set {
static_assert(ENTT_PAGE_SIZE && ((ENTT_PAGE_SIZE & (ENTT_PAGE_SIZE - 1)) == 0), "ENTT_PAGE_SIZE must be a power of two");
static constexpr auto entt_per_page = ENTT_PAGE_SIZE / sizeof(Entity);

using traits_type = entt_traits<std::underlying_type_t<Entity>>;
using traits_type = entt_traits<Entity>;
using page_type = std::unique_ptr<Entity[]>;

class sparse_set_iterator final {
Expand Down
4 changes: 2 additions & 2 deletions src/entt/entity/storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class storage: public sparse_set<Entity> {
static_assert(std::is_move_constructible_v<Type> && std::is_move_assignable_v<Type>, "The managed type must be at least move constructible and assignable");

using underlying_type = sparse_set<Entity>;
using traits_type = entt_traits<std::underlying_type_t<Entity>>;
using traits_type = entt_traits<Entity>;

template<bool Const>
class storage_iterator final {
Expand Down Expand Up @@ -478,7 +478,7 @@ class storage: public sparse_set<Entity> {
/*! @copydoc storage */
template<typename Entity, typename Type>
class storage<Entity, Type, std::enable_if_t<ENTT_IS_EMPTY(Type)>>: public sparse_set<Entity> {
using traits_type = entt_traits<std::underlying_type_t<Entity>>;
using traits_type = entt_traits<Entity>;
using underlying_type = sparse_set<Entity>;

public:
Expand Down

0 comments on commit 371b541

Please sign in to comment.