From 3d798c5fc738768493df925d1f5d72256f2dec4e Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 27 Mar 2024 20:27:30 +0100 Subject: Encoder: Encoder::As requires the object to implement the As method. Signed-off-by: Amlal El Mahrouss --- Private/NewKit/Defines.hpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Private/NewKit/Defines.hpp b/Private/NewKit/Defines.hpp index 18506e8f..af87e377 100644 --- a/Private/NewKit/Defines.hpp +++ b/Private/NewKit/Defines.hpp @@ -88,7 +88,8 @@ inline Args &&move(Args &&arg) { return static_cast(arg); } -/// @brief Encoding class +/// @brief Encoder class +/// Used to cast A to B or B to A. class Encoder final { public: explicit Encoder() = default; @@ -98,14 +99,23 @@ public: Encoder(const Encoder &) = default; public: + /// @brief Convert type to bytes. + /// @tparam T the type. + /// @param type (a1) the data. + /// @return a1 as Char* template Char* AsBytes(T type) noexcept { return reinterpret_cast(type); } + /// @brief Convert T class to Y class. + /// @tparam T the class type of type. + /// @tparam Y the result class. + /// @param type the class to cast. + /// @return the class as Y. template Y As(T type) noexcept { - return reinterpret_cast(type); + return type.template As(); } }; -- cgit v1.2.3