aboutsummaryrefslogtreecommitdiff
path: root/include/salticidae/stream.h
diff options
context:
space:
mode:
authorDeterminant <ted.sybil@gmail.com>2018-07-12 18:04:52 -0400
committerDeterminant <ted.sybil@gmail.com>2018-07-12 18:04:52 -0400
commit53f4c5137da249e5e955809ffe32afa3cf5c3522 (patch)
tree0b187dc8e2d2d86a223ab79c42bdc471c40bc569 /include/salticidae/stream.h
parent33faa8e355dc47a126790f1ea3e52d1813aedc69 (diff)
...
Diffstat (limited to 'include/salticidae/stream.h')
-rw-r--r--include/salticidae/stream.h19
1 files changed, 15 insertions, 4 deletions
diff --git a/include/salticidae/stream.h b/include/salticidae/stream.h
index 9e4791c..b5e0757 100644
--- a/include/salticidae/stream.h
+++ b/include/salticidae/stream.h
@@ -52,15 +52,26 @@ class DataStream {
buffer(other.buffer),
offset(other.offset) {}
+ void swap(DataStream &other) {
+ std::swap(buffer, other.buffer);
+ std::swap(offset, other.offset);
+ }
+
DataStream &operator=(const DataStream &other) {
- buffer = other.buffer;
- offset = other.offset;
+ if (this != &other)
+ {
+ DataStream tmp(other);
+ tmp.swap(*this);
+ }
return *this;
}
DataStream &operator=(DataStream &&other) {
- buffer = std::move(other.buffer);
- offset = other.offset;
+ if (this != &other)
+ {
+ DataStream tmp(std::move(other));
+ tmp.swap(*this);
+ }
return *this;
}