added type_list_size and type_list_size_v
This commit is contained in:
@@ -10,15 +10,32 @@
|
||||
namespace entt {
|
||||
|
||||
|
||||
/*! @brief A class to use to push around lists of types, nothing more. */
|
||||
template<typename...>
|
||||
struct type_list {};
|
||||
|
||||
|
||||
/*! @brief Primary template isn't defined on purpose. */
|
||||
template<typename>
|
||||
struct type_list_size;
|
||||
|
||||
|
||||
/**
|
||||
* @brief A class to use to push around lists of types, nothing more.
|
||||
* @tparam Type Types provided by the given type list.
|
||||
* @brief Compile-time number of elements in a type list.
|
||||
* @tparam Type Types provided by the type list.
|
||||
*/
|
||||
template<typename... Type>
|
||||
struct type_list {
|
||||
/*! @brief Unsigned integer type. */
|
||||
static constexpr auto size = sizeof...(Type);
|
||||
};
|
||||
struct type_list_size<type_list<Type...>>
|
||||
: std::integral_constant<std::size_t, sizeof...(Type)>
|
||||
{};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Helper variable template.
|
||||
* @tparam List Type list.
|
||||
*/
|
||||
template<class List>
|
||||
constexpr auto type_list_size_v = type_list_size<List>::value;
|
||||
|
||||
|
||||
/*! @brief Primary template isn't defined on purpose. */
|
||||
@@ -145,9 +162,6 @@ struct is_named_type<Type, std::void_t<named_type_traits_t<std::decay_t<Type>>>>
|
||||
|
||||
/**
|
||||
* @brief Helper variable template.
|
||||
*
|
||||
* True if a given type has a name, false otherwise.
|
||||
*
|
||||
* @tparam Type Potentially named type.
|
||||
*/
|
||||
template<class Type>
|
||||
|
||||
@@ -5,8 +5,8 @@ TEST(TypeList, Functionalities) {
|
||||
using type = entt::type_list<int, char>;
|
||||
using other = entt::type_list<double>;
|
||||
|
||||
ASSERT_EQ((type::size), (decltype(type::size){2}));
|
||||
ASSERT_EQ((other::size), (decltype(other::size){1}));
|
||||
ASSERT_EQ(entt::type_list_size_v<type>, 2u);
|
||||
ASSERT_EQ(entt::type_list_size_v<other>, 1u);
|
||||
ASSERT_TRUE((std::is_same_v<entt::type_list_cat_t<type, other, type, other>, entt::type_list<int, char, double, int, char, double>>));
|
||||
ASSERT_TRUE((std::is_same_v<entt::type_list_cat_t<type, other>, entt::type_list<int, char, double>>));
|
||||
ASSERT_TRUE((std::is_same_v<entt::type_list_cat_t<type, type>, entt::type_list<int, char, int, char>>));
|
||||
|
||||
Reference in New Issue
Block a user