Skip to content

Commit

Permalink
move-semantics, defaulting, and noexcept
Browse files Browse the repository at this point in the history
  • Loading branch information
gabyx committed Dec 19, 2018
1 parent 40ea9fc commit 365aae5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
10 changes: 7 additions & 3 deletions include/crossguid/guid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ class Guid
Guid(const unsigned char *bytes);
Guid(const std::string &fromString);
Guid();
Guid(const Guid &other);
Guid &operator=(const Guid &other);

Guid(const Guid &other) = default;
Guid &operator=(const Guid &other) = default;
Guid(Guid &&other) = default;
Guid &operator=(Guid &&other) = default;

bool operator==(const Guid &other) const;
bool operator!=(const Guid &other) const;

Expand Down Expand Up @@ -105,7 +109,7 @@ namespace std
// Template specialization for std::swap<Guid>() --
// See guid.cpp for the function definition
template <>
void swap(xg::Guid &guid0, xg::Guid &guid1);
void swap(xg::Guid &guid0, xg::Guid &guid1) noexcept;

// Specialization for std::hash<Guid> -- this implementation
// uses std::hash<std::string> on the stringification of the guid
Expand Down
13 changes: 1 addition & 12 deletions src/guid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,23 +245,12 @@ Guid::Guid(const std::string &fromString)
Guid::Guid() : _bytes{ {0} }
{ }

// copy constructor
Guid::Guid(const Guid &other) : _bytes(other._bytes)
{ }

// set all bytes to zero
void Guid::zeroify()
{
std::fill(_bytes.begin(), _bytes.end(), static_cast<unsigned char>(0));
}

// overload assignment operator
Guid &Guid::operator=(const Guid &other)
{
Guid(other).swap(*this);
return *this;
}

// overload equality operator
bool Guid::operator==(const Guid &other) const
{
Expand Down Expand Up @@ -408,7 +397,7 @@ END_XG_NAMESPACE
namespace std
{
template <>
void swap(xg::Guid &lhs, xg::Guid &rhs)
void swap(xg::Guid &lhs, xg::Guid &rhs) noexcept
{
lhs.swap(rhs);
}
Expand Down

0 comments on commit 365aae5

Please sign in to comment.