Browse Source

Fixed equality of the STL allocators (#1079)

Jorrit Rouwe 1 year ago
parent
commit
5914c576a6
3 changed files with 20 additions and 5 deletions
  1. 6 0
      Jolt/Core/STLAlignedAllocator.h
  2. 6 0
      Jolt/Core/STLAllocator.h
  3. 8 5
      Jolt/Core/STLTempAllocator.h

+ 6 - 0
Jolt/Core/STLAlignedAllocator.h

@@ -25,6 +25,12 @@ public:
 	using size_type = size_t;
 	using difference_type = ptrdiff_t;
 
+	/// The allocator is stateless
+	using is_always_equal = std::true_type;
+
+	/// Allocator supports moving
+	using propagate_on_container_move_assignment = std::true_type;
+
 	/// Constructor
 	inline					STLAlignedAllocator() = default;
 

+ 6 - 0
Jolt/Core/STLAllocator.h

@@ -27,6 +27,12 @@ public:
 	using size_type = size_t;
 	using difference_type = ptrdiff_t;
 
+	/// The allocator is stateless
+	using is_always_equal = std::true_type;
+
+	/// Allocator supports moving
+	using propagate_on_container_move_assignment = std::true_type;
+
 	/// Constructor
 	inline					STLAllocator() = default;
 

+ 8 - 5
Jolt/Core/STLTempAllocator.h

@@ -27,6 +27,9 @@ public:
 	using size_type = size_t;
 	using difference_type = ptrdiff_t;
 
+	/// The allocator is not stateless (depends on the temp allocator)
+	using is_always_equal = std::false_type;
+
 	/// Constructor
 	inline					STLTempAllocator(TempAllocator &inAllocator) : mAllocator(inAllocator) { }
 
@@ -46,15 +49,15 @@ public:
 		mAllocator.Free(inPointer, uint(inN * sizeof(value_type)));
 	}
 
-	/// Allocators are stateless so assumed to be equal
-	inline bool				operator == (const STLTempAllocator<T> &) const
+	/// Allocators are not-stateless, assume if allocator address matches that the allocators are the same
+	inline bool				operator == (const STLTempAllocator<T> &inRHS) const
 	{
-		return true;
+		return &mAllocator == &inRHS.mAllocator;
 	}
 
-	inline bool				operator != (const STLTempAllocator<T> &) const
+	inline bool				operator != (const STLTempAllocator<T> &inRHS) const
 	{
-		return false;
+		return &mAllocator != &inRHS.mAllocator;
 	}
 
 	/// Converting to allocator for other type