This commit is contained in:
blueloveTH 2024-02-18 23:41:16 +08:00
parent 4cfe93ee51
commit a79d4e0d38
2 changed files with 8 additions and 13 deletions

View File

@ -21,7 +21,7 @@ public:
unique_ptr_128(T* ptr): ptr(ptr) {} unique_ptr_128(T* ptr): ptr(ptr) {}
T* operator->() const { return ptr; } T* operator->() const { return ptr; }
T* get() const { return ptr; } T* get() const { return ptr; }
T* release() { T* p = ptr; ptr = nullptr; return p; } T* detach() { T* p = ptr; ptr = nullptr; return p; }
unique_ptr_128(const unique_ptr_128&) = delete; unique_ptr_128(const unique_ptr_128&) = delete;
unique_ptr_128& operator=(const unique_ptr_128&) = delete; unique_ptr_128& operator=(const unique_ptr_128&) = delete;
@ -32,14 +32,14 @@ public:
~unique_ptr_128(){ PK_POOL128_DELETE(ptr) } ~unique_ptr_128(){ PK_POOL128_DELETE(ptr) }
template<typename U> template<typename U>
unique_ptr_128(unique_ptr_128<U>&& other): ptr(other.release()) {} unique_ptr_128(unique_ptr_128<U>&& other): ptr(other.detach()) {}
operator bool() const { return ptr != nullptr; } operator bool() const { return ptr != nullptr; }
template<typename U> template<typename U>
unique_ptr_128& operator=(unique_ptr_128<U>&& other) { unique_ptr_128& operator=(unique_ptr_128<U>&& other) {
PK_POOL128_DELETE(ptr) PK_POOL128_DELETE(ptr)
ptr = other.release(); ptr = other.detach();
return *this; return *this;
} }
@ -53,6 +53,11 @@ public:
typedef unique_ptr_128<Expr> Expr_; typedef unique_ptr_128<Expr> Expr_;
typedef small_vector<Expr_, 6> Expr_vector; typedef small_vector<Expr_, 6> Expr_vector;
template<>
struct TriviallyRelocatable<Expr_>{
constexpr static bool value = true;
};
struct Expr{ struct Expr{
int line = 0; int line = 0;
virtual ~Expr() = default; virtual ~Expr() = default;

View File

@ -190,21 +190,11 @@ namespace pkpy {
constexpr inline bool is_trivially_relocatable_v = constexpr inline bool is_trivially_relocatable_v =
TriviallyRelocatable<T>::value; TriviallyRelocatable<T>::value;
template<typename T>
struct TriviallyRelocatable<std::unique_ptr<T>>{
constexpr static bool value = true;
};
template<typename T> template<typename T>
struct TriviallyRelocatable<std::shared_ptr<T>>{ struct TriviallyRelocatable<std::shared_ptr<T>>{
constexpr static bool value = true; constexpr static bool value = true;
}; };
template<typename T>
struct TriviallyRelocatable<std::weak_ptr<T>>{
constexpr static bool value = true;
};
template<typename T> template<typename T>
struct TriviallyRelocatable<std::vector<T>>{ struct TriviallyRelocatable<std::vector<T>>{
constexpr static bool value = true; constexpr static bool value = true;