Răsfoiți Sursa

type_traits: added type_identity trait (waiting for C++20)

Michele Caini 5 ani în urmă
părinte
comite
dda8c209df
1 a modificat fișierele cu 23 adăugiri și 0 ștergeri
  1. 23 0
      src/entt/core/type_traits.hpp

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

@@ -12,6 +12,29 @@
 namespace entt {
 
 
+/**
+ * @brief Identity type trait.
+ *
+ * Useful to establish non-deduced contexts in template argument deduction
+ * (waiting for C++20) or to provide types through function arguments.
+ *
+ * @tparam Type A type.
+ */
+template<typename Type>
+struct type_identity {
+    /*! @brief Identity type. */
+    using type = Type;
+};
+
+
+/**
+ * @brief Helper type.
+ * @tparam Type A type.
+ */
+template<typename Type>
+using type_identity_t = typename type_identity<Type>::type;
+
+
 /**
  * @brief A type-only `sizeof` wrapper that returns 0 where `sizeof` complains.
  * @tparam Type The type of which to return the size.