From e47540ea4de4fae4cf6a30c42b38cafd1067ff80 Mon Sep 17 00:00:00 2001 From: "John K. Luebs" Date: Wed, 13 Nov 2024 01:31:07 -0600 Subject: [PATCH] Add/remove necessary special member functions Quite surprising to find the PFFFT C++ class had a non-deleted copy constructor. Add move/move assignment to make this a little nicer to work with. --- pffft/pffft.hpp | 54 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/pffft/pffft.hpp b/pffft/pffft.hpp index 28e9db1..e353078 100644 --- a/pffft/pffft.hpp +++ b/pffft/pffft.hpp @@ -167,7 +167,18 @@ public: */ Fft( int length, int stackThresholdLen = 4096 ); - + Fft(const Fft&) = delete; + Fft& operator=(const Fft&) = delete; + Fft(Fft&& other) : setup(std::move(other.setup)), work(other.work), + length(other.length), stackThresholdLen(other.stackThresholdLen) { + other.work = nullptr; + other.length = 0; + }; + Fft& operator=(Fft&& other) { + std::swap(setup, other.setup); + std::swap(work, other.work); + return *this; + }; /* * constructor or prepareLength() produced a valid FFT instance? * delivers false for invalid FFT sizes @@ -388,7 +399,7 @@ public: private: detail::Setup setup; - Scalar* work; + Scalar* work{}; int length; int stackThresholdLen; }; @@ -439,6 +450,15 @@ public: Setup() : self(NULL) {} + Setup(const Setup&) = delete; + Setup& operator=(const Setup&) = delete; + Setup(Setup&& other) : self(other.self) { + other.self = nullptr; + } + Setup& operator=(Setup&& other) { + std::swap(self, other.self); + return *this; + } ~Setup() { pffft_destroy_setup(self); } @@ -503,6 +523,15 @@ public: Setup() : self(NULL) {} + Setup(const Setup&) = delete; + Setup& operator=(const Setup&) = delete; + Setup(Setup&& other) : self(other.self) { + other.self = nullptr; + } + Setup& operator=(Setup&& other) { + std::swap(self, other.self); + return *this; + } ~Setup() { pffft_destroy_setup(self); } @@ -563,6 +592,15 @@ public: Setup() : self(NULL) {} + Setup(const Setup&) = delete; + Setup& operator=(const Setup&) = delete; + Setup(Setup&& other) : self(other.self) { + other.self = nullptr; + } + Setup& operator=(Setup&& other) { + std::swap(self, other.self); + return *this; + } ~Setup() { pffftd_destroy_setup(self); } @@ -629,6 +667,15 @@ public: Setup() : self(NULL) {} + Setup(const Setup&) = delete; + Setup& operator=(const Setup&) = delete; + Setup(Setup&& other) : self(other.self) { + other.self = nullptr; + } + Setup& operator=(Setup&& other) { + std::swap(self, other.self); + return *this; + } ~Setup() { pffftd_destroy_setup(self); } @@ -687,8 +734,7 @@ public: template inline Fft::Fft(int length, int stackThresholdLen) - : work(NULL) - , length(0) + : length(0) , stackThresholdLen(stackThresholdLen) { #if (__cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900))