Skip to content

Commit

Permalink
constructor changes for non-trivial types
Browse files Browse the repository at this point in the history
  • Loading branch information
kernelwernel committed Oct 14, 2024
1 parent 8713459 commit 390b2d7
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/vmaware.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,45 @@ struct VM {

Result(double dbl) : type(ResultType::Double), doubleValue(dbl) {}

Result(const Result& other) : type(other.type) {
if (type == ResultType::String) {
new (&strValue) std::string(other.strValue);
} else if (type == ResultType::Integer) {
intValue = other.intValue;
} else if (type == ResultType::Double) {
doubleValue = other.doubleValue;
}
}

Result& operator=(const Result& other) {
if (this != &other) {
if (type == ResultType::String) {
strValue.~basic_string();
}
type = other.type;
if (type == ResultType::String) {
new (&strValue) std::string(other.strValue);
} else if (type == ResultType::Integer) {
intValue = other.intValue;
} else if (type == ResultType::Double) {
doubleValue = other.doubleValue;
}
}
return *this;
}













~Result() {
if (type == ResultType::String) {
strValue.~basic_string();
Expand Down

0 comments on commit 390b2d7

Please sign in to comment.