Skip to content
Snippets Groups Projects
Commit 02bc6f13 authored by Olivier BICHLER's avatar Olivier BICHLER
Browse files

Added AnyPtr for possible future use

parent fca8066f
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,45 @@ ...@@ -19,6 +19,45 @@
#include "aidge/utils/ErrorHandling.hpp" #include "aidge/utils/ErrorHandling.hpp"
namespace Aidge { 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 * This class manages the raw data storage of a Tensor and provide generic copy
* primitives from other devices and from/to host. * primitives from other devices and from/to host.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment