From 53f4c5137da249e5e955809ffe32afa3cf5c3522 Mon Sep 17 00:00:00 2001 From: Determinant Date: Thu, 12 Jul 2018 18:04:52 -0400 Subject: ... --- include/salticidae/stream.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'include/salticidae/stream.h') 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; } -- cgit v1.2.3