Add another rvalue constructor to the String class

refs #12555
This commit is contained in:
Gunnar Beutner 2016-08-31 12:48:49 +02:00
parent 7e293b004f
commit 54f0cb2c2c
3 changed files with 27 additions and 0 deletions

View File

@ -29,6 +29,23 @@ REGISTER_BUILTIN_TYPE(String, String::GetPrototype());
const String::SizeType String::NPos = std::string::npos; const String::SizeType String::NPos = std::string::npos;
String::String(Value&& other)
{
*this = std::move(other);
}
String& String::operator=(Value&& other)
{
const String *p = other.GetPtr<String>();
if (p)
m_Data = std::move(p->m_Data);
else
m_Data = other;
return *this;
}
String& String::operator+=(const Value& rhs) String& String::operator+=(const Value& rhs)
{ {
m_Data += static_cast<String>(rhs); m_Data += static_cast<String>(rhs);

View File

@ -85,6 +85,8 @@ public:
: m_Data(std::move(other.m_Data)) : m_Data(std::move(other.m_Data))
{ } { }
String(Value&& other);
inline ~String(void) inline ~String(void)
{ } { }
@ -105,6 +107,8 @@ public:
return *this; return *this;
} }
String& operator=(Value&& rhs);
inline String& operator=(const std::string& rhs) inline String& operator=(const std::string& rhs)
{ {
m_Data = rhs; m_Data = rhs;

View File

@ -286,6 +286,12 @@ public:
return boost::get<T>(m_Value); return boost::get<T>(m_Value);
} }
template<typename T>
const T *GetPtr(void) const
{
return &boost::get<T>(m_Value);
}
private: private:
boost::variant<boost::blank, double, bool, String, Object::Ptr> m_Value; boost::variant<boost::blank, double, bool, String, Object::Ptr> m_Value;
}; };