mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
fix a bug of any
This commit is contained in:
parent
182177482f
commit
89fa6c9d3f
@ -14,7 +14,7 @@ struct any{
|
|||||||
inline static vtable* get(){
|
inline static vtable* get(){
|
||||||
static_assert(std::is_same_v<T, std::decay_t<T>>);
|
static_assert(std::is_same_v<T, std::decay_t<T>>);
|
||||||
if constexpr (is_sso_v<T>){
|
if constexpr (is_sso_v<T>){
|
||||||
static vtable vt{ typeid(T), [](void*){} };
|
static vtable vt{ typeid(T), nullptr };
|
||||||
return &vt;
|
return &vt;
|
||||||
}else{
|
}else{
|
||||||
static vtable vt{ typeid(T), [](void* ptr){ delete static_cast<T*>(ptr); } };
|
static vtable vt{ typeid(T), [](void* ptr){ delete static_cast<T*>(ptr); } };
|
||||||
@ -28,7 +28,7 @@ struct any{
|
|||||||
|
|
||||||
any() : data(nullptr), _vt(nullptr) {}
|
any() : data(nullptr), _vt(nullptr) {}
|
||||||
|
|
||||||
explicit operator bool() const { return data != nullptr; }
|
explicit operator bool() const { return _vt != nullptr; }
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
any(T&& value){
|
any(T&& value){
|
||||||
@ -52,7 +52,7 @@ struct any{
|
|||||||
any(const any& other) = delete;
|
any(const any& other) = delete;
|
||||||
any& operator=(const any& other) = delete;
|
any& operator=(const any& other) = delete;
|
||||||
|
|
||||||
~any() { if(data) _vt->deleter(data); }
|
~any() { if(_vt && _vt->deleter) _vt->deleter(data); }
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T& _cast() const noexcept{
|
T& _cast() const noexcept{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user