named types (traits and macros) are no longer available

This commit is contained in:
Michele Caini
2019-12-01 23:14:35 +01:00
parent c3b0fa6c93
commit b25b1c45fb
5 changed files with 0 additions and 164 deletions

View File

@@ -169,59 +169,6 @@ template<class Type>
constexpr auto is_equality_comparable_v = is_equality_comparable<Type>::value;
/*! @brief Traits class used mainly to push things across boundaries. */
template<typename>
struct named_type_traits;
/**
* @brief Specialization used to get rid of constness.
* @tparam Type Named type.
*/
template<typename Type>
struct named_type_traits<const Type>
: named_type_traits<Type>
{};
/**
* @brief Helper type.
* @tparam Type Potentially named type.
*/
template<typename Type>
using named_type_traits_t = typename named_type_traits<Type>::type;
/**
* @brief Helper variable template.
* @tparam Type Potentially named type.
*/
template<class Type>
constexpr auto named_type_traits_v = named_type_traits<Type>::value;
/**
* @brief Provides the member constant `value` to true if a given type has a
* name. In all other cases, `value` is false.
* @tparam Type Potentially named type.
*/
template<typename Type, typename = std::void_t<>>
struct is_named_type: std::false_type {};
/*! @copydoc is_named_type */
template<typename Type>
struct is_named_type<Type, std::void_t<named_type_traits_t<std::decay_t<Type>>>>: std::true_type {};
/**
* @brief Helper variable template.
* @tparam Type Potentially named type.
*/
template<class Type>
constexpr auto is_named_type_v = is_named_type<Type>::value;
/**
* @brief Defines an enum class to use for opaque identifiers and a dedicate
* `to_integer` function to convert the identifiers to their underlying type.
@@ -239,95 +186,4 @@ constexpr auto is_named_type_v = is_named_type<Type>::value;
}
/**
* @brief Utility macro to deal with an issue of MSVC.
*
* See _msvc-doesnt-expand-va-args-correctly_ on SO for all the details.
*
* @param args Argument to expand.
*/
#define ENTT_EXPAND(args) args
/**
* @brief Makes an already existing type a named type.
*
* The current definition contains a workaround for Clang 6 because it fails to
* deduce correctly the type to use to specialize the class template.<br/>
* With a compiler that fully supports C++17 and works fine with deduction
* guides, the following should be fine instead:
*
* @code{.cpp}
* std::integral_constant<ENTT_ID_TYPE, entt::basic_hashed_string{#type}>
* @endcode
*
* In order to support even sligthly older compilers, I prefer to stick to the
* implementation below.
*
* @param type Type to assign a name to.
*/
#define ENTT_NAMED_TYPE(type)\
template<>\
struct entt::named_type_traits<type>\
: std::integral_constant<ENTT_ID_TYPE, entt::basic_hashed_string<std::remove_cv_t<std::remove_pointer_t<std::decay_t<decltype(#type)>>>>{#type}>\
{\
static_assert(std::is_same_v<std::remove_cv_t<type>, type>);\
static_assert(std::is_object_v<type>);\
}
/**
* @brief Defines a named type (to use for structs).
* @param clazz Name of the type to define.
* @param body Body of the type to define.
*/
#define ENTT_NAMED_STRUCT_ONLY(clazz, body)\
struct clazz body;\
ENTT_NAMED_TYPE(clazz)
/**
* @brief Defines a named type (to use for structs).
* @param ns Namespace where to define the named type.
* @param clazz Name of the type to define.
* @param body Body of the type to define.
*/
#define ENTT_NAMED_STRUCT_WITH_NAMESPACE(ns, clazz, body)\
namespace ns { struct clazz body; }\
ENTT_NAMED_TYPE(ns::clazz)
/*! @brief Utility function to simulate macro overloading. */
#define ENTT_NAMED_STRUCT_OVERLOAD(_1, _2, _3, FUNC, ...) FUNC
/*! @brief Defines a named type (to use for structs). */
#define ENTT_NAMED_STRUCT(...) ENTT_EXPAND(ENTT_NAMED_STRUCT_OVERLOAD(__VA_ARGS__, ENTT_NAMED_STRUCT_WITH_NAMESPACE, ENTT_NAMED_STRUCT_ONLY,)(__VA_ARGS__))
/**
* @brief Defines a named type (to use for classes).
* @param clazz Name of the type to define.
* @param body Body of the type to define.
*/
#define ENTT_NAMED_CLASS_ONLY(clazz, body)\
class clazz body;\
ENTT_NAMED_TYPE(clazz)
/**
* @brief Defines a named type (to use for classes).
* @param ns Namespace where to define the named type.
* @param clazz Name of the type to define.
* @param body Body of the type to define.
*/
#define ENTT_NAMED_CLASS_WITH_NAMESPACE(ns, clazz, body)\
namespace ns { class clazz body; }\
ENTT_NAMED_TYPE(ns::clazz)
/*! @brief Utility function to simulate macro overloading. */
#define ENTT_NAMED_CLASS_MACRO(_1, _2, _3, FUNC, ...) FUNC
/*! @brief Defines a named type (to use for classes). */
#define ENTT_NAMED_CLASS(...) ENTT_EXPAND(ENTT_NAMED_CLASS_MACRO(__VA_ARGS__, ENTT_NAMED_CLASS_WITH_NAMESPACE, ENTT_NAMED_CLASS_ONLY,)(__VA_ARGS__))
#endif // ENTT_CORE_TYPE_TRAITS_HPP

View File

@@ -1,10 +1,6 @@
#include <gtest/gtest.h>
#include <entt/core/type_traits.hpp>
ENTT_NAMED_TYPE(int);
ENTT_NAMED_STRUCT(named_struct, {});
ENTT_NAMED_CLASS(named_class, {});
TEST(Choice, Functionalities) {
ASSERT_TRUE((std::is_base_of_v<entt::choice_t<0>, entt::choice_t<1>>));
ASSERT_FALSE((std::is_base_of_v<entt::choice_t<1>, entt::choice_t<0>>));
@@ -26,14 +22,3 @@ TEST(IsEqualityComparable, Functionalities) {
ASSERT_TRUE(entt::is_equality_comparable_v<int>);
ASSERT_FALSE(entt::is_equality_comparable_v<void>);
}
TEST(NamedTypes, Functionalities) {
ASSERT_TRUE(entt::is_named_type_v<int>);
ASSERT_TRUE(entt::is_named_type_v<named_struct>);
ASSERT_TRUE(entt::is_named_type_v<named_class>);
ASSERT_FALSE(entt::is_named_type_v<char>);
ASSERT_EQ(entt::named_type_traits_t<int>::value, "int"_hs);
ASSERT_EQ(entt::named_type_traits_t<named_struct>::value, "named_struct"_hs);
ASSERT_EQ(entt::named_type_traits_t<named_class>::value, "named_class"_hs);
}

View File

@@ -11,7 +11,6 @@
#include <entt/entity/entity.hpp>
ENTT_OPAQUE_TYPE(opaque, std::uint64_t);
ENTT_NAMED_TYPE(int);
struct empty_type {};

View File

@@ -7,8 +7,6 @@ struct an_event {};
struct another_event {};
struct one_more_event {};
ENTT_NAMED_TYPE(an_event);
struct receiver {
static void forward(entt::dispatcher &dispatcher, const an_event &event) {
dispatcher.enqueue(event);

View File

@@ -8,8 +8,6 @@ struct foo_event { int i; char c; };
struct bar_event {};
struct quux_event {};
ENTT_NAMED_TYPE(foo_event);
TEST(Emitter, Clear) {
test_emitter emitter;