diff --git a/include/verilated_types.h b/include/verilated_types.h index b39b3e2ae..044848e5e 100644 --- a/include/verilated_types.h +++ b/include/verilated_types.h @@ -1113,7 +1113,7 @@ public: refCountInc(); } VlClassRef(VlClassRef&& moved) - : m_objp{std::exchange(moved.m_objp, nullptr)} {} + : m_objp{vlstd::exchange(moved.m_objp, nullptr)} {} ~VlClassRef() { refCountDec(); } // METHODS @@ -1126,7 +1126,7 @@ public: } VlClassRef& operator=(VlClassRef&& moved) { refCountDec(); - m_objp = std::exchange(moved.m_objp, nullptr); + m_objp = vlstd::exchange(moved.m_objp, nullptr); return *this; } template @@ -1139,7 +1139,7 @@ public: template VlClassRef& operator=(VlClassRef&& moved) { refCountDec(); - m_objp = std::exchange(moved.m_objp, nullptr); + m_objp = vlstd::exchange(moved.m_objp, nullptr); return *this; } // Dynamic caster diff --git a/include/verilatedos.h b/include/verilatedos.h index c5677b992..2e1456852 100644 --- a/include/verilatedos.h +++ b/include/verilatedos.h @@ -540,6 +540,8 @@ using ssize_t = uint32_t; ///< signed size_t; returned from read() //========================================================================= // Conversions +#include + namespace vlstd { template @@ -564,6 +566,14 @@ T const& as_const(T& v) { return v; } +// C++14's std::exchange +template +T exchange(T& obj, U&& new_value) { + T old_value = std::move(obj); + obj = std::forward(new_value); + return old_value; +} + }; // namespace vlstd //=========================================================================