BAN: Add destructor to function if it needs to deallocate something someday
This commit is contained in:
		
							parent
							
								
									9b8de5025a
								
							
						
					
					
						commit
						99cf1c0330
					
				|  | @ -13,7 +13,7 @@ namespace BAN | ||||||
| 	class Function<Ret(Args...)> | 	class Function<Ret(Args...)> | ||||||
| 	{ | 	{ | ||||||
| 	public: | 	public: | ||||||
| 		Function() {} | 		Function() = default; | ||||||
| 		Function(Ret(*function)(Args...)) | 		Function(Ret(*function)(Args...)) | ||||||
| 		{ | 		{ | ||||||
| 			static_assert(sizeof(CallablePointer) <= m_size); | 			static_assert(sizeof(CallablePointer) <= m_size); | ||||||
|  | @ -38,6 +38,11 @@ namespace BAN | ||||||
| 			new (m_storage) CallableLambda<Lambda>(lambda); | 			new (m_storage) CallableLambda<Lambda>(lambda); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|  | 		~Function() | ||||||
|  | 		{ | ||||||
|  | 			clear(); | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
| 		Ret operator()(Args... args) | 		Ret operator()(Args... args) | ||||||
| 		{ | 		{ | ||||||
| 			ASSERT(*this); | 			ASSERT(*this); | ||||||
|  | @ -52,6 +57,13 @@ namespace BAN | ||||||
| 			return false; | 			return false; | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
|  | 		void clear() | ||||||
|  | 		{ | ||||||
|  | 			if (*this) | ||||||
|  | 				reinterpret_cast<CallableBase*>(m_storage)->~CallableBase(); | ||||||
|  | 			memset(m_storage, 0, m_size); | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
| 	private: | 	private: | ||||||
| 		struct CallableBase | 		struct CallableBase | ||||||
| 		{ | 		{ | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue