Skip to content

Commit

Permalink
[C++] Add move ctor/assign op to Status (#1134)
Browse files Browse the repository at this point in the history
* [C++] Add move ctor/assign op to Status

* format
  • Loading branch information
PragmaTwice authored Nov 23, 2023
1 parent 2109401 commit 7ec6a45
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/fury/util/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ class Status {

// Copy the specified status.
Status(const Status &s);
void operator=(const Status &s);
Status &operator=(const Status &s);

// Move the specified status.
Status(Status &&s);
Status &operator=(Status &&s);

// Return a success status.
static Status OK() { return Status(); }
Expand Down Expand Up @@ -172,11 +176,25 @@ static inline std::ostream &operator<<(std::ostream &os, const Status &x) {
inline Status::Status(const Status &s)
: state_((s.state_ == nullptr) ? nullptr : new State(*s.state_)) {}

inline void Status::operator=(const Status &s) {
inline Status &Status::operator=(const Status &s) {
// The following condition catches both aliasing (when this == &s),
// and the common case where both s and *this are ok.
if (state_ != s.state_) {
CopyFrom(s.state_);
}
return *this;
}

inline Status::Status(Status &&s) : state_(s.state_) { s.state_ = nullptr; }

inline Status &Status::operator=(Status &&s) {
// The following condition catches both aliasing (when this == &s),
// and the common case where both s and *this are ok.
if (state_ != s.state_) {
delete state_;
state_ = s.state_;
s.state_ = nullptr;
}
return *this;
}
} // namespace fury

0 comments on commit 7ec6a45

Please sign in to comment.