Ver Fonte

Variant: Use perfect forwarding. Fixes bug where we could get moved from an lvalue reference.

Michael Ragazzon há 6 anos atrás
pai
commit
cef60e8106
2 ficheiros alterados com 2 adições e 24 exclusões
  1. 0 4
      Include/RmlUi/Core/Variant.h
  2. 2 20
      Include/RmlUi/Core/Variant.inl

+ 0 - 4
Include/RmlUi/Core/Variant.h

@@ -81,14 +81,10 @@ public:
 
 	// Construct by variant type
 	template< typename T >
-	Variant(const T& t);
-	template< typename T >
 	Variant(T&& t);
 
 	// Assign by variant type
 	template<typename T>
-	Variant& operator=(const T& t);
-	template<typename T>
 	Variant& operator=(T&& t);
 
 	void Clear();

+ 2 - 20
Include/RmlUi/Core/Variant.inl

@@ -34,35 +34,17 @@ inline Variant::Type Variant::GetType() const
 	return type;
 }
 
-// Constructs a variant with internal data.
-template< typename T >
-Variant::Variant(const T& t) : type(NONE)
-{
-	Set(t);
-}
-
-// Constructs a variant by moving data
 template< typename T >
 Variant::Variant(T&& t) : type(NONE)
 {
-	Set(std::move(t));
-}
-
-// Clear and set new value
-template< typename T >
-Variant& Variant::operator=(const T& t)
-{
-	Clear();
-	Set(t);
-	return *this;
+	Set(std::forward<T>(t));
 }
 
-// Clear and set new value
 template< typename T >
 Variant& Variant::operator=(T&& t)
 {
 	Clear();
-	Set(std::move(t));
+	Set(std::forward<T>(t));
 	return *this;
 }