おもちゃクラスのムーブ コンストラクターの実装中に、次のパターンに気付きました。
array2D(array2D&& that)
{
data_ = that.data_;
that.data_ = 0;
height_ = that.height_;
that.height_ = 0;
width_ = that.width_;
that.width_ = 0;
size_ = that.size_;
that.size_ = 0;
}
パターンは明らかに次のとおりです。
member = that.member;
that.member = 0;
そこで、スティーリングの冗長性を減らし、エラーを起こしにくくするプリプロセッサ マクロを作成しました。
#define STEAL(member) member = that.member; that.member = 0;
実装は次のようになります。
array2D(array2D&& that)
{
STEAL(data_);
STEAL(height_);
STEAL(width_);
STEAL(size_);
}
これには欠点がありますか?プリプロセッサを必要としないよりクリーンなソリューションはありますか?