`const`オブジェクトで` std :: move`を使用できるのはなぜですか?
C ++ 11では、次のコードを記述できます。 struct Cat { Cat(){} }; const Cat cat; std::move(cat); //this is valid in C++11 を呼び出すとstd::move、オブジェクトを移動することを意味します。つまり、オブジェクトを変更します。移動するにはconstオブジェクトは不合理ですが、なぜstd::moveこの動作を制限しないのですか?将来的には罠になりますよね? ここでトラップとは、ブランドンがコメントで言及したとおりです。 「彼はそれが彼をこっそりとこっそりと「罠にかける」ことを意味していると思う。もし彼が気付かないと、彼は結局彼が意図したものではないコピーで終わるからだ。」 スコットマイヤーズの著書「Effective Modern C ++」で、彼は例を挙げています。 class Annotation { public: explicit Annotation(const std::string text) : value(std::move(text)) //here we want to call string(string&&), //but because text is const, //the return type of std::move(text) …