Why does declaring a move constructor noexcept change how std::vector relocates its elements when the buffer grows?
Correct answer
A. vector then moves elements instead of copying them, which keeps the strong guarantee
15 views
A. vector then moves elements instead of copying them, which keeps the strong guarantee
15 views
Move_if_noexcept is the rule at work: vector must preserve its strong exception guarantee, so it relocates by move only when the move constructor is noexcept or copying is unavailable. Otherwise every reallocation copies the elements, so a missing noexcept on a hand-written move constructor quietly costs performance. Declaring a destructor or a move member by hand can also suppress the implicitly declared move constructor.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is A? Ask here and get an explanation.