[glibmm] Glib::ustring: Add move operators
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm] Glib::ustring: Add move operators
- Date: Thu, 14 Jan 2016 18:01:13 +0000 (UTC)
commit c72c8e709888e0bd2bd58bb5d96354d352bd0c5f
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date: Thu Jan 14 18:59:06 2016 +0100
Glib::ustring: Add move operators
Bug #760282
glib/glibmm/ustring.cc | 34 ++++++++++++++++++++++++++++++----
glib/glibmm/ustring.h | 21 +++++++++++++++++++--
2 files changed, 49 insertions(+), 6 deletions(-)
---
diff --git a/glib/glibmm/ustring.cc b/glib/glibmm/ustring.cc
index e8d7511..78b0e5b 100644
--- a/glib/glibmm/ustring.cc
+++ b/glib/glibmm/ustring.cc
@@ -1,6 +1,3 @@
-// -*- c++ -*-
-/* $Id$ */
-
/* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
@@ -27,7 +24,8 @@
#include <algorithm>
#include <iostream>
#include <cstring>
-# include <stdexcept>
+#include <stdexcept>
+#include <utility> // For std::move()
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -298,6 +296,11 @@ ustring::ustring(const ustring& other)
string_ (other.string_)
{}
+ustring::ustring(ustring&& other)
+:
+ string_ (std::move(other.string_))
+{}
+
ustring::ustring(const ustring& src, ustring::size_type i, ustring::size_type n)
:
string_ ()
@@ -345,6 +348,11 @@ ustring::ustring(const std::string& src)
string_ (src)
{}
+ustring::ustring(std::string&& src)
+:
+ string_ (std::move(src))
+{}
+
ustring::~ustring() noexcept
{}
@@ -362,12 +370,24 @@ ustring& ustring::operator=(const ustring& other)
return *this;
}
+ustring& ustring::operator=(ustring&& other)
+{
+ string_ = std::move(other.string_);
+ return *this;
+}
+
ustring& ustring::operator=(const std::string& src)
{
string_ = src;
return *this;
}
+ustring& ustring::operator=(std::string&& src)
+{
+ string_ = std::move(src);
+ return *this;
+}
+
ustring& ustring::operator=(const char* src)
{
string_ = src;
@@ -396,6 +416,12 @@ ustring& ustring::assign(const ustring& src)
return *this;
}
+ustring& ustring::assign(ustring&& src)
+{
+ string_ = std::move(src.string_);
+ return *this;
+}
+
ustring& ustring::assign(const ustring& src, ustring::size_type i, ustring::size_type n)
{
const Utf8SubstrBounds bounds (src.string_, i, n);
diff --git a/glib/glibmm/ustring.h b/glib/glibmm/ustring.h
index a4e2fa8..528a536 100644
--- a/glib/glibmm/ustring.h
+++ b/glib/glibmm/ustring.h
@@ -268,21 +268,36 @@ public:
*/
ustring(const ustring& other);
- /*! Assign the value of another string to this string.
+ /*! Construct a ustring by moving from another ustring.
+ * @param other A source string.
+ */
+ ustring(ustring&& other);
+
+ /*! Assign the value of another string by copying to this string.
* @param other A source string.
*/
ustring& operator=(const ustring& other);
+ /*! Assign the value of another string by moving to this string.
+ * @param other A source string.
+ */
+ ustring& operator=(ustring&& other);
+
/*! Swap contents with another string.
* @param other String to swap with.
*/
void swap(ustring& other);
- /*! Construct a ustring as a copy of another std::string.
+ /*! Construct a ustring as a copy of a std::string.
* @param src A source <tt>std::string</tt> containing text encoded as UTF-8.
*/
ustring(const std::string& src);
+ /*! Construct a ustring by moving from a std::string.
+ * @param src A source <tt>std::string</tt> containing text encoded as UTF-8.
+ */
+ ustring(std::string&& src);
+
/*! Construct a ustring as a copy of a substring.
* @param src %Source ustring.
* @param i Index of first character to copy from.
@@ -324,11 +339,13 @@ public:
//! @{
ustring& operator=(const std::string& src);
+ ustring& operator=(std::string&& src);
ustring& operator=(const char* src);
ustring& operator=(gunichar uc);
ustring& operator=(char c);
ustring& assign(const ustring& src);
+ ustring& assign(ustring&& src);
ustring& assign(const ustring& src, size_type i, size_type n);
ustring& assign(const char* src, size_type n);
ustring& assign(const char* src);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]