Implementierung der B = f (A) -Syntax durch Move-Zuweisung
Ich habe eine Matrix-Klasse mit einer Move-Zuweisung als implementiert
template <typename OutType>
class Matrix
{
public:
int Rows_; // number of Rows
int Columns_; // number of Columns
OutType *data_; // row Major order allocation
// STUFF
Matrix<OutType> & operator=(Matrix<float>&& other) {
swap(other);
return *this;
}
void swap(Matrix<float>& other) {
int t_Rows_ = Rows_; Rows_ = other.Rows_; other.Rows_ = t_Rows_;
int t_Columns_ = Columns_; Columns_ = other.Columns_; other.Columns_ = t_Columns_;
float* t_ptr = data_;
data_ = other.data_;
other.data_ = t_ptr; }
}
um das umzusetzenB=f(A);
Syntax, wie in vorgeschlagen
C ++: Implementierung von B = f (A), wobei B- und A-Arrays und B bereits definiert sind
Als mögliche Funktion betrachte ich die FFT, implementiert als
Matrix<float> FFT(const Matrix<float> &in)
{
Matrix<float> out(in.GetRows(),in.GetColumns());
// STUFF
return out;
}
Gibt es Raum für weitere Effizienzverbesserungen? Gibt es noch einen weiteren Trick, um zum Beispiel die Zugzuordnung oder das zu verbessern?swap
Funktion?
EDIT: NEUE LÖSUNG NACH KONRAD RUDOLPHS KOMMENTAR
Matrix & operator=(Matrix&& other) {
std::swap(Rows_, other.Rows_);
std::swap(Columns_, other.Columns_);
std::swap(data_, other.data_);
std::cout << "move assigned \n";
return *this;
}