Browse Source

type_traits: added is_transparent[_v] utility

Michele Caini 4 years ago
parent
commit
acb2d332ea
2 changed files with 27 additions and 0 deletions
  1. 19 0
      src/entt/core/type_traits.hpp
  2. 8 0
      test/entt/core/type_traits.cpp

+ 19 - 0
src/entt/core/type_traits.hpp

@@ -509,6 +509,25 @@ struct is_ebco_eligible
 template<typename Type>
 inline constexpr bool is_ebco_eligible_v = is_ebco_eligible<Type>::value;
 
+/**
+ * @brief Provides the member constant `value` to true if `Type::is_transparent`
+ * is valid and denotes a type, false otherwise.
+ * @tparam Type The type to test.
+ */
+template<typename Type, typename = void>
+struct is_transparent: std::false_type {};
+
+/*! @copydoc is_transparent */
+template<typename Type>
+struct is_transparent<Type, std::void_t<typename Type::is_transparent>>: std::true_type {};
+
+/**
+ * @brief Helper variable template.
+ * @tparam Type The type to test.
+ */
+template<typename Type>
+inline constexpr bool is_transparent_v = is_transparent<Type>::value;
+
 /**
  * @cond TURN_OFF_DOXYGEN
  * Internal details not to be documented.

+ 8 - 0
test/entt/core/type_traits.cpp

@@ -1,3 +1,4 @@
+#include <functional>
 #include <iterator>
 #include <tuple>
 #include <type_traits>
@@ -160,6 +161,13 @@ TEST(TypeTraits, IsEBCOEligible) {
     static_assert(!entt::is_ebco_eligible_v<void>);
 }
 
+TEST(TypeTraits, IsTransparent) {
+    static_assert(!entt::is_transparent_v<std::less<int>>);
+    static_assert(entt::is_transparent_v<std::less<void>>);
+    static_assert(!entt::is_transparent_v<std::logical_not<double>>);
+    static_assert(entt::is_transparent_v<std::logical_not<void>>);
+}
+
 TEST(TypeTraits, ConstnessAs) {
     static_assert(std::is_same_v<entt::constness_as_t<int, char>, int>);
     static_assert(std::is_same_v<entt::constness_as_t<const int, char>, int>);