Sfoglia il codice sorgente

Use std::unique_ptr to manage internal Pushable implementation

Ole 9 anni fa
parent
commit
1fa9ed9dbc
1 ha cambiato i file con 7 aggiunte e 14 eliminazioni
  1. 7 14
      lib/luwra/types.hpp

+ 7 - 14
lib/luwra/types.hpp

@@ -457,24 +457,17 @@ namespace internal {
  * A value which may be pushed onto the stack.
  */
 struct Pushable {
-	internal::PushableI* interface;
+	std::unique_ptr<internal::PushableI> interface;
 
 	template <typename T> inline
-	Pushable(T value): interface(new internal::PushableT<T>(value)) {}
-
-	inline
-	Pushable(Pushable&& other): interface(other.interface) {
-		other.interface = nullptr;
-	}
-
-	inline
-	Pushable(const Pushable& other): interface(other.interface->copy()) {}
+	Pushable(T&& value):
+		interface(new internal::PushableT<T>(std::forward<T>(value)))
+	{}
 
 	inline
-	~Pushable() {
-		if (interface)
-			delete interface;
-	}
+	Pushable(const Pushable& other):
+		interface(other.interface->copy())
+	{}
 
 	inline
 	bool operator <(const Pushable& other) const {