diff options
author | Max Kellermann <max@duempel.org> | 2013-12-03 12:57:22 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-12-03 12:59:33 +0100 |
commit | c36af357303891a45fdcb286b99ca8bb5be20693 (patch) | |
tree | 7a242dc4f251b2b1f964e1544d977aa32979fc9d /src | |
parent | 424f478c3f6760023ff67ca4facc424787be5a0d (diff) | |
download | mpd-c36af357303891a45fdcb286b99ca8bb5be20693.tar.gz mpd-c36af357303891a45fdcb286b99ca8bb5be20693.tar.xz mpd-c36af357303891a45fdcb286b99ca8bb5be20693.zip |
TagBuilder: add move operator
Diffstat (limited to '')
-rw-r--r-- | src/tag/TagBuilder.cxx | 31 | ||||
-rw-r--r-- | src/tag/TagBuilder.hxx | 3 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/tag/TagBuilder.cxx b/src/tag/TagBuilder.cxx index 47921f248..2d3b49eb5 100644 --- a/src/tag/TagBuilder.cxx +++ b/src/tag/TagBuilder.cxx @@ -72,6 +72,37 @@ TagBuilder::operator=(const TagBuilder &other) return *this; } +TagBuilder & +TagBuilder::operator=(TagBuilder &&other) +{ + time = other.time; + has_playlist = other.has_playlist; + items = std::move(other.items); + + return *this; +} + +TagBuilder & +TagBuilder::operator=(Tag &&other) +{ + time = other.time; + has_playlist = other.has_playlist; + + /* move all TagItem pointers from the Tag object; we don't + need to contact the tag pool, because all we do is move + references */ + items.clear(); + items.reserve(other.num_items); + std::copy_n(other.items, other.num_items, std::back_inserter(items)); + + /* discard the pointers from the Tag object */ + other.num_items = 0; + delete[] other.items; + other.items = nullptr; + + return *this; +} + void TagBuilder::Clear() { diff --git a/src/tag/TagBuilder.hxx b/src/tag/TagBuilder.hxx index 63a4c175a..cd4fa4e57 100644 --- a/src/tag/TagBuilder.hxx +++ b/src/tag/TagBuilder.hxx @@ -68,6 +68,9 @@ public: explicit TagBuilder(Tag &&other); TagBuilder &operator=(const TagBuilder &other); + TagBuilder &operator=(TagBuilder &&other); + + TagBuilder &operator=(Tag &&other); /** * Returns true if the tag contains no items. This ignores the "time" |