move-constructor

Call to implicitly deleted copy constructor

感情迁移 提交于 2021-02-11 12:13:04
问题 I have the following setup: class MyClass { public: static MyClass Clone(const MyClass& other) { return MyClass(other, 10); } static MyClass CreateNormal(int x, int y) { return MyClass(int x, int y); } // There are a few more factory functions. private: // Constructor 1 MyClass(int x, int y) : b_(x, y) {} // Constructor 2 MyClass(const MyClass& other, int c) : b_(other.b_, c) {} // And a lot more constructors. // NotMyClass has its copy constructor deleted. NotMyClass b_; } int main() {

Does C++11 standard require implementers to prioritize noexcept move constructor over const copy constructor for std::vector?

点点圈 提交于 2021-02-07 07:16:53
问题 Reading this and this and 23.3.6.5/1 of the standard, where in the latest C++ standard draft is it specified that implementers should prioritize the use of non-throwing move-constructor T(T &&t) noexcept over a const copy-constructor T(const T &t) when std::vector<T> re-allocates its element as a result of a push_back operation? Is it 13.3.3.1.4/1 on overload resolution of reference binding? EDIT 1 I argue on 13.3.3.1.4/1 because of the following reasons: 13.3/2 Overload resolution selects

Does C++11 standard require implementers to prioritize noexcept move constructor over const copy constructor for std::vector?

时光怂恿深爱的人放手 提交于 2021-02-07 07:16:37
问题 Reading this and this and 23.3.6.5/1 of the standard, where in the latest C++ standard draft is it specified that implementers should prioritize the use of non-throwing move-constructor T(T &&t) noexcept over a const copy-constructor T(const T &t) when std::vector<T> re-allocates its element as a result of a push_back operation? Is it 13.3.3.1.4/1 on overload resolution of reference binding? EDIT 1 I argue on 13.3.3.1.4/1 because of the following reasons: 13.3/2 Overload resolution selects

Move Constructor & Move Assignment

China☆狼群 提交于 2021-01-27 16:02:41
问题 I have been reading the book "The C++ programing language 4th edition" by Bjarne Stroustrup (The creator of c++) and have been learning about move constructors and move assignments. In the book for the class vector (see 1 for header below) he shows how to implement the move constructor (see 2 below) and says the move assignment is implemented in a similar manner but doesn't show how. I have implemented the move assignment myself (see 3 below) and everything seems to be working fine, however,

Move constructors and multiple inheritance

偶尔善良 提交于 2021-01-21 06:29:49
问题 Synopsis How can I safely design a move constructor when a class uses multiple inheritance? Details Consider the following scenario: struct T { }; struct U { }; struct X : public T, public U { X(X&& other) : T(std::move(other)) , U(std::move(other)) // already moved?! { } }; Is there a way to move-construct both T and U safely? 回答1: tl;dr : the code in the question is ok. The code above is fine, because std::move itself doesn't actually change other in any way, it just does a cast to make