Skip to content

Commit

Permalink
Update delegate.impl.hpp
Browse files Browse the repository at this point in the history
  • Loading branch information
oktonion committed Sep 15, 2024
1 parent 1cf2331 commit bf68c6c
Showing 1 changed file with 21 additions and 33 deletions.
54 changes: 21 additions & 33 deletions delegates/delegate.impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,28 +420,25 @@ namespace delegates
if (this == &other)
return;

// swap for caller
{
// swap for caller
{
caller_type tmp = caller_;
caller_ = other.caller_;
other.caller_ = tmp;
}
// swap for comparator
{
comparator_type tmp = comparator_;
comparator_ = other.comparator_;
other.comparator_ = tmp;
}
// swap for arrays
{
unsigned char tmp[sizeof(union_)];
std::memcpy(tmp, union_, sizeof(union_));
std::memcpy(union_, other.union_, sizeof(union_));
std::memcpy(other.union_, tmp, sizeof(union_));
}
caller_type tmp = caller_;
caller_ = other.caller_;
other.caller_ = tmp;
}
// swap for comparator
{
comparator_type tmp = comparator_;
comparator_ = other.comparator_;
other.comparator_ = tmp;
}
// swap for arrays
{
unsigned char tmp[sizeof(union_)];
std::memcpy(tmp, union_, sizeof(union_));
std::memcpy(union_, other.union_, sizeof(union_));
std::memcpy(other.union_, tmp, sizeof(union_));
}

}

friend void swap(delegate& lhs, delegate& rhs)
Expand All @@ -451,18 +448,9 @@ namespace delegates

delegate(const delegate &other)
{
if (other.caller_)
{
caller_ = (other.caller_);
comparator_ = (other.comparator_);
std::memcpy(union_, other.union_, sizeof(union_));
}
else
{
caller_ = NULL;
comparator_ = NULL;
std::memset(union_, 0, sizeof(union_));
}
caller_ = (other.caller_);
comparator_ = (other.comparator_);
std::memcpy(union_, other.union_, sizeof(union_));
}

delegate& operator=(const delegate &other)
Expand All @@ -477,7 +465,7 @@ namespace delegates

bool operator!() const
{
return NULL == caller_;
return NULL == caller_ || NULL == comparator_;
}

bool operator==(const delegate &other) const
Expand Down

0 comments on commit bf68c6c

Please sign in to comment.