75 questions
0 votes
2 answers
234 views
Why is copy-and-swap preferred over self-assignment check? [closed]
What is the copy-and-swap idiom? lists copy-and-swap as a better alternative to self-assignment check, being simpler and providing stronger exception guarantees. Performance aside, are there any ...
3 votes
2 answers
219 views
What is the rationale behind the C++ compiler’s rules for implicitly declaring special member functions?
I came across this table describing how the C++ compiler implicitly declares special member functions depending on which ones the user has explicitly declared: Source: Howard Hinnant - How I Declare ...
2 votes
1 answer
188 views
Why can't a struct with a reference member have default move assignment operator?
I know this may be obvious to many, but please explain it to me: struct MyFoo { MyFoo(int& arg) : ref(arg) {} int& ref; MyFoo& operator= (MyFoo&& other) = default; ...
0 votes
1 answer
113 views
Does the compiler generate the move operations (not default) in case of a default destructor? [duplicate]
A relatively same question is asked before, but the code snippet is different, which I believe makes this question unique. Does the compiler generate the move operations in the following scenario? ...
0 votes
0 answers
86 views
Is there a caveat for using placement new instead of move assignment for a emplace_back imitation on a static array
I was trying to implement an emplace_back method for a statically-sized array (for fun). I came across the problem of whether I should use placement-new or move assignment for this emplace back method....
1 vote
0 answers
17 views
What is the causing my buffer to overrun?
Somehow in one of or more of my loops are overrunning my buffer but I can't catch it. It's either that or somehow my capacity or size is at 0 when it shouldn't be but either way I can't find the issue ...
0 votes
0 answers
114 views
Does the Copy and Swap idiom have a not-required swap?
In an answer to this question, under the label: "Why does that work?" , it was noted that: Now, if other is being initialized with an rvalue, it will be move-constructed. Perfect. In the ...
0 votes
1 answer
142 views
The move semantics and time complexity of nested std::vector<std::vector<std::string>> rvalue assignment
If there is function with the following signature: std::vector<std::vector<std::string>> some_func(); And its assigned to a variable of the same type: std::vector<std::vector<std::...
0 votes
0 answers
166 views
Identification of automatically generated move assignment operator
What is the automatically generated move assignment operator for a class Number that contains only one attribute of type std::shared_ptr<Vertex>? #include <iostream> #include <memory>...
1 vote
1 answer
89 views
C++ implicitly declared move assignment operator calling implicitly declared copy assignment operator of base class
A simple question but I can not find the set of rules that proves that the behavior of the following code example is correct. It seems here that only strDerived is moved from b, but strBase is copied? ...
1 vote
3 answers
245 views
Can I reliably emplace_back in a vector of a type that does not have an assignment operator?
I made some tests in GCC, Clang and MSVC and found out that emplace_back never calls an assignment operator on the contained class. It only calls the copy or move constructor when reallocation takes ...
4 votes
1 answer
1k views
When is `noexcept` required on move assignment?
I recently realized (pretty late in fact) that it's important to have move constructors marked as noexcept, so that std containers are allowed to avoid copying. What puzzles me is why if I do an erase(...
1 vote
1 answer
2k views
Explicitly defaulted copy/move assignment operators implicitly deleted because field has no copy/move operators. C++ [duplicate]
I'm new to C++ and dont know why this is happening and how to fix it. Here's some snippets of the code: header file: class Dictionary{ private: string filename; const ...
0 votes
0 answers
201 views
AUTOSAR C++ Rule 6-2-1 - Move and Copy Assignment Operators
The following code violates AUTOSAR C++ rule 6-2-1: Move and copy assignment operators shall either move or respectively copy base classes and data members of a class, without any side effects. Move ...
6 votes
1 answer
672 views
std::vector move assignment vs move construction: why is the state of 'other' not consistent?
For move construction: After the move, other is guaranteed to be empty(). 1 For move assignment, the oft-quoted: other is in a valid but unspecified state afterwards. 2 Why is the state of other ...