any: review copy, prepare for #652

This commit is contained in:
Michele Caini
2021-02-06 23:22:32 +01:00
parent 1b53e83dde
commit fd989feea3

View File

@@ -46,8 +46,9 @@ class any {
switch(op) {
case operation::COPY:
as<any>(to).vtable = from.vtable;
case operation::MOVE:
return (as<any>(to).instance = from.instance);
as<any>(to).instance = from.instance;
case operation::DTOR:
break;
case operation::COMP:
@@ -78,7 +79,8 @@ class any {
switch(op) {
case operation::COPY:
if constexpr(std::is_copy_constructible_v<Type>) {
return new (&as<any>(to).storage) Type{std::as_const(*instance)};
as<any>(to).vtable = from.vtable;
new (&as<any>(to).storage) Type{std::as_const(*instance)};
}
break;
case operation::MOVE:
@@ -108,7 +110,8 @@ class any {
switch(op) {
case operation::COPY:
if constexpr(std::is_copy_constructible_v<Type>) {
return (as<any>(to).instance = new Type{*static_cast<const Type *>(from.instance)});
as<any>(to).vtable = from.vtable;
as<any>(to).instance = new Type{*static_cast<const Type *>(from.instance)};
}
break;
case operation::MOVE:
@@ -200,9 +203,7 @@ public:
any(const any &other)
: any{}
{
if(other.vtable(operation::COPY, other, this)) {
vtable = other.vtable;
}
other.vtable(operation::COPY, other, this);
}
/**