Open zdzhaoyong opened 2 years ago
Why not unique_ptr return cpptype.
template <typename T> class SvarValue_<std::shared_ptr<T>>: public SvarValue{ public: explicit SvarValue_(const std::shared_ptr<T>& v):_var(v){} explicit SvarValue_(std::shared_ptr<T>&& v):_var(std::move(v)){} virtual TypeID cpptype()const{return typeid(T);} virtual SvarClass* classObject()const{return SvarClass::instance<T>();} virtual Svar clone(int depth=0)const{return _var;} virtual const void* as(const TypeID& tp)const{ if(tp==typeid(T)) return _var.get(); else if(tp==typeid(std::shared_ptr<T>)) return &_var; else return nullptr; } std::shared_ptr<T> _var; }; template <typename T> class SvarValue_<std::unique_ptr<T>>: public SvarValue{ public: explicit SvarValue_(std::unique_ptr<T>&& v):_var(std::move(v)){} virtual SvarClass* classObject()const{return SvarClass::instance<T>();} virtual const void* as(const TypeID& tp)const{ if(tp==typeid(T)) return _var.get(); else if(tp==typeid(std::unique_ptr<T>)) return &_var; else return nullptr; } std::unique_ptr<T> _var; };
Why not unique_ptr return cpptype.