mirror of
https://github.com/ETLCPP/etl.git
synced 2026-11-09 14:49:53 +08:00
Only destruct the content if the new value is of a different type.
This commit is contained in:
parent
e3ef9e1ae6
commit
80d111712f
@ -726,9 +726,20 @@ namespace etl
|
||||
{
|
||||
STATIC_ASSERT(Type_Is_Supported<T>::value, "Unsupported type");
|
||||
|
||||
destruct_current();
|
||||
new(static_cast<T*>(data)) T(value);
|
||||
type_id = Type_Id_Lookup<T>::type_id;
|
||||
// Assigning the same type as last time?
|
||||
if (type_id == Type_Id_Lookup<T>::type_id)
|
||||
{
|
||||
// Do a simple copy.
|
||||
*static_cast<T*>(data) = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
// We must destruct the old type, as the new one is different.
|
||||
destruct_current();
|
||||
new(static_cast<T*>(data)) T(value);
|
||||
type_id = Type_Id_Lookup<T>::type_id;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user