diff --git a/include/aidge/backend/TensorImpl.hpp b/include/aidge/backend/TensorImpl.hpp index 981bb9e43e61de1b07d5ff2e97cccea78a19ac56..bc33616a5c23b92344439574f3e3b3f107d1ac6e 100644 --- a/include/aidge/backend/TensorImpl.hpp +++ b/include/aidge/backend/TensorImpl.hpp @@ -19,6 +19,45 @@ #include "aidge/utils/ErrorHandling.hpp" namespace Aidge { +/** + * This is a thin wrapper around std::any that can only hold pointers. + * It also handles the case where a U* pointer is stored and a const U* pointer + * is requested, which is legit (std::any would throw a bad_cast exception in + * this case). + * Note: not used yet, put in reserve here for possible future use. +*/ +/* +class AnyPtr { +public: + template <typename T, typename = std::enable_if_t<std::is_pointer<T>::value>> + constexpr inline AnyPtr(T value) : data(value), ptrToConst(std::is_const<std::remove_pointer_t<T>>::value) {} + + // Requested T is "U*" + template <typename T, typename std::enable_if<std::is_same<std::remove_pointer_t<T>, std::remove_const_t<std::remove_pointer_t<T>>>::value>::type* = nullptr> + constexpr inline T get() const { + // data has to be "U*" + return future_std::any_cast<T>(data); + } + + // Requested T is "const U*" + template <typename T, typename std::enable_if<!std::is_same<std::remove_pointer_t<T>, std::remove_const_t<std::remove_pointer_t<T>>>::value>::type* = nullptr> + constexpr inline T get() const { + if (ptrToConst) { + // data is "const U*" => OK, no bad cast + return future_std::any_cast<T>(data); + } + else { + // data is "U*" => need to remove const from request to avoid bad cast + return future_std::any_cast<std::add_pointer_t<std::remove_const_t<std::remove_pointer_t<T>>>>(data); + } + } + +private: + const future_std::any data; + const bool ptrToConst; +}; +*/ + /** * This class manages the raw data storage of a Tensor and provide generic copy * primitives from other devices and from/to host.