diff --git a/src/entt/core/type_traits.hpp b/src/entt/core/type_traits.hpp index 10c0a2dc1..e0a2676e5 100644 --- a/src/entt/core/type_traits.hpp +++ b/src/entt/core/type_traits.hpp @@ -3,8 +3,9 @@ #include -#include +#include #include +#include #include "../config/config.h" #include "fwd.hpp" @@ -469,7 +470,7 @@ template /** * @brief Provides the member constant `value` to true if a given type is * equality comparable, false otherwise. - * @tparam Type Potentially equality comparable type. + * @tparam Type The type to test. */ template struct is_equality_comparable: std::bool_constant(choice<2>)> {}; @@ -477,7 +478,7 @@ struct is_equality_comparable: std::bool_constant inline constexpr auto is_equality_comparable_v = is_equality_comparable::value; @@ -499,11 +500,11 @@ struct is_applicable>: std::is_invocable {}; /** -* @copybrief is_applicable -* @tparam Func A valid function type. -* @tparam Tuple Tuple-like type. -* @tparam Args The list of arguments to use to probe the function type. -*/ + * @copybrief is_applicable + * @tparam Func A valid function type. + * @tparam Tuple Tuple-like type. + * @tparam Args The list of arguments to use to probe the function type. + */ template class Tuple, typename... Args> struct is_applicable>: std::is_invocable {}; @@ -545,10 +546,10 @@ inline constexpr auto is_applicable_r_v = is_applicable_r::valu /** -* @brief Provides the member constant `value` to true if a given type is -* complete, false otherwise. -* @tparam Type Potential complete type. -*/ + * @brief Provides the member constant `value` to true if a given type is + * complete, false otherwise. + * @tparam Type The type to test. + */ template struct is_complete: std::false_type {}; @@ -559,13 +560,70 @@ struct is_complete>: std::true_type {} /** -* @brief Helper variable template. -* @tparam Type Potential complete type. -*/ + * @brief Helper variable template. + * @tparam Type The type to test. + */ template inline constexpr auto is_complete_v = is_complete::value; +/** + * @brief Provides the member constant `value` to true if a given type is an + * iterator, false otherwise. + * @tparam Type The type to test. + */ +template +struct is_iterator: std::false_type {}; + + +/*! @copydoc is_iterator */ +template +struct is_iterator::iterator_category>> + : std::true_type +{}; + + +/** + * @brief Helper variable template. + * @tparam Type The type to test. + */ +template +inline constexpr auto is_iterator_v = is_iterator::value; + + +/** + * @brief Provides the member constant `value` to true if a given type is of the + * required iterator type, false otherwise. + * @tparam Type The type to test. + * @tparam It Required iterator type. + */ +template +struct is_iterator_type: std::false_type {}; + + +/*! @copydoc is_iterator_type */ +template +struct is_iterator_type && std::is_same_v>> + : std::true_type +{}; + + +/*! @copydoc is_iterator_type */ +template +struct is_iterator_type> + : is_iterator_type +{}; + + +/** + * @brief Helper variable template. + * @tparam Type The type to test. + * @tparam It Required iterator type. + */ +template +inline constexpr auto is_iterator_type_v = is_iterator_type::value; + + /** * @brief Transcribes the constness of a type to another type. * @tparam To The type to which to transcribe the constness. diff --git a/test/entt/core/type_traits.cpp b/test/entt/core/type_traits.cpp index 237005ded..0329d3574 100644 --- a/test/entt/core/type_traits.cpp +++ b/test/entt/core/type_traits.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -100,14 +101,13 @@ TEST(TypeTraits, IsEqualityComparable) { static_assert(entt::is_equality_comparable_v>>); static_assert(entt::is_equality_comparable_v>); static_assert(entt::is_equality_comparable_v>>); + static_assert(entt::is_equality_comparable_v); static_assert(!entt::is_equality_comparable_v); static_assert(!entt::is_equality_comparable_v>); static_assert(!entt::is_equality_comparable_v>>); static_assert(!entt::is_equality_comparable_v>); static_assert(!entt::is_equality_comparable_v>>); - - static_assert(entt::is_equality_comparable_v); static_assert(!entt::is_equality_comparable_v); } @@ -121,8 +121,28 @@ TEST(TypeTraits, IsApplicable) { } TEST(TypeTraits, IsComplete) { - static_assert(entt::is_complete_v); static_assert(!entt::is_complete_v); + static_assert(entt::is_complete_v); +} + +TEST(TypeTraits, IsIterator) { + static_assert(!entt::is_iterator_v); + static_assert(!entt::is_iterator_v); + + static_assert(entt::is_iterator_v); + static_assert(entt::is_iterator_v::iterator>); + static_assert(entt::is_iterator_v::const_iterator>); + static_assert(entt::is_iterator_v::reverse_iterator>); +} + +TEST(TypeTraits, IsIteratorType) { + static_assert(!entt::is_iterator_type_v::iterator>); + static_assert(!entt::is_iterator_type_v::iterator, std::vector::const_iterator>); + static_assert(!entt::is_iterator_type_v::iterator, int *>); + + static_assert(entt::is_iterator_type_v::iterator, std::vector::iterator>); + static_assert(entt::is_iterator_type_v::iterator, std::reverse_iterator::iterator>>); + static_assert(entt::is_iterator_type_v::iterator, std::reverse_iterator::iterator>>>); } TEST(TypeTraits, ConstnessAs) {