[gtkmm] Gdk::TimeCoord: Fix copy and move assignment
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm] Gdk::TimeCoord: Fix copy and move assignment
- Date: Wed, 26 Jul 2017 08:46:12 +0000 (UTC)
commit 8b5cd8e3fbce7f8dfa4bdc6f51efdff647abad24
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date: Wed Jul 26 10:42:05 2017 +0200
Gdk::TimeCoord: Fix copy and move assignment
Use the technique with a temporary object and swap(). It's easy and safe,
and it handles self assignment.
gdk/src/timecoord.ccg | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
---
diff --git a/gdk/src/timecoord.ccg b/gdk/src/timecoord.ccg
index d90b43c..b25464c 100644
--- a/gdk/src/timecoord.ccg
+++ b/gdk/src/timecoord.ccg
@@ -16,6 +16,7 @@
*/
#include <gdk/gdk.h>
+#include <utility> // std::move(), std::swap()
namespace
{
@@ -43,8 +44,8 @@ TimeCoord::TimeCoord(const TimeCoord& other)
TimeCoord& TimeCoord::operator=(const TimeCoord& other)
{
- g_free(gobject_);
- gobject_ = time_coord_copy(other.gobject_);
+ TimeCoord temp(other);
+ std::swap(gobject_, temp.gobject_);
return *this;
}
@@ -57,9 +58,8 @@ TimeCoord::TimeCoord(TimeCoord&& other) noexcept
TimeCoord& TimeCoord::operator=(TimeCoord&& other) noexcept
{
- g_free(gobject_);
- gobject_ = std::move(other.gobject_);
- other.gobject_ = nullptr;
+ TimeCoord temp(std::move(other));
+ std::swap(gobject_, temp.gobject_);
return *this;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]