From 1b66460638fc7296cda04e8d961b3d247aa9106f Mon Sep 17 00:00:00 2001 From: Maxim Prokhorov Date: Sun, 27 Sep 2020 02:56:12 +0300 Subject: [PATCH] sns: be more explicit about the copy vs. move --- code/espurna/sensor.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/code/espurna/sensor.cpp b/code/espurna/sensor.cpp index add5769d..e32ba159 100644 --- a/code/espurna/sensor.cpp +++ b/code/espurna/sensor.cpp @@ -220,6 +220,13 @@ struct sensor_magnitude_t { constexpr static double _unset = std::numeric_limits::quiet_NaN(); static unsigned char _counts[MAGNITUDE_MAX]; + sensor_magnitude_t& operator=(const sensor_magnitude_t&) = default; + + void move(sensor_magnitude_t&& other) noexcept { + *this = other; + other.filter = nullptr; + } + public: static unsigned char counts(unsigned char type) { @@ -227,15 +234,18 @@ struct sensor_magnitude_t { } sensor_magnitude_t() = delete; - sensor_magnitude_t& operator=(const sensor_magnitude_t&) = default; - sensor_magnitude_t(const sensor_magnitude_t&) = delete; sensor_magnitude_t(sensor_magnitude_t&& other) noexcept { *this = other; other.filter = nullptr; } - ~sensor_magnitude_t() { + sensor_magnitude_t& operator=(sensor_magnitude_t&& other) noexcept { + move(std::move(other)); + return *this; + } + + ~sensor_magnitude_t() noexcept { delete filter; }