Internals: Use C++14 exchange

This commit is contained in:
Wilson Snyder 2024-01-28 19:45:07 -05:00
parent e3e5f30ba1
commit eecdf4b0f3
2 changed files with 6 additions and 6 deletions

View File

@ -1648,7 +1648,7 @@ public:
} }
// cppcheck-suppress noExplicitConstructor // cppcheck-suppress noExplicitConstructor
VlClassRef(VlClassRef&& moved) VlClassRef(VlClassRef&& moved)
: m_objp{vlstd::exchange(moved.m_objp, nullptr)} {} : m_objp{std::exchange(moved.m_objp, nullptr)} {}
// cppcheck-suppress noExplicitConstructor // cppcheck-suppress noExplicitConstructor
template <typename T_OtherClass> template <typename T_OtherClass>
VlClassRef(const VlClassRef<T_OtherClass>& copied) VlClassRef(const VlClassRef<T_OtherClass>& copied)
@ -1658,7 +1658,7 @@ public:
// cppcheck-suppress noExplicitConstructor // cppcheck-suppress noExplicitConstructor
template <typename T_OtherClass> template <typename T_OtherClass>
VlClassRef(VlClassRef<T_OtherClass>&& moved) VlClassRef(VlClassRef<T_OtherClass>&& moved)
: m_objp{vlstd::exchange(moved.m_objp, nullptr)} {} : m_objp{std::exchange(moved.m_objp, nullptr)} {}
~VlClassRef() { refCountDec(); } ~VlClassRef() { refCountDec(); }
// METHODS // METHODS
@ -1673,7 +1673,7 @@ public:
VlClassRef& operator=(VlClassRef&& moved) { VlClassRef& operator=(VlClassRef&& moved) {
if (m_objp == moved.m_objp) return *this; if (m_objp == moved.m_objp) return *this;
refCountDec(); refCountDec();
m_objp = vlstd::exchange(moved.m_objp, nullptr); m_objp = std::exchange(moved.m_objp, nullptr);
return *this; return *this;
} }
template <typename T_OtherClass> template <typename T_OtherClass>
@ -1688,7 +1688,7 @@ public:
VlClassRef& operator=(VlClassRef<T_OtherClass>&& moved) { VlClassRef& operator=(VlClassRef<T_OtherClass>&& moved) {
if (m_objp == moved.m_objp) return *this; if (m_objp == moved.m_objp) return *this;
refCountDec(); refCountDec();
m_objp = vlstd::exchange(moved.m_objp, nullptr); m_objp = std::exchange(moved.m_objp, nullptr);
return *this; return *this;
} }
// Assign with nullptr // Assign with nullptr

View File

@ -109,12 +109,12 @@ class DfgGraph final {
// cppcheck-suppress noExplicitConstructor // cppcheck-suppress noExplicitConstructor
UserDataInUse(UserDataInUse&& that) { UserDataInUse(UserDataInUse&& that) {
UASSERT(that.m_graphp, "Moving from empty"); UASSERT(that.m_graphp, "Moving from empty");
m_graphp = vlstd::exchange(that.m_graphp, nullptr); m_graphp = std::exchange(that.m_graphp, nullptr);
} }
VL_UNCOPYABLE(UserDataInUse); VL_UNCOPYABLE(UserDataInUse);
UserDataInUse& operator=(UserDataInUse&& that) { UserDataInUse& operator=(UserDataInUse&& that) {
UASSERT(that.m_graphp, "Moving from empty"); UASSERT(that.m_graphp, "Moving from empty");
m_graphp = vlstd::exchange(that.m_graphp, nullptr); m_graphp = std::exchange(that.m_graphp, nullptr);
return *this; return *this;
} }