Multiple ChoiceIntermediate 45s
noexcept effect on move_if_noexcept
Why does `std::vector` prefer to move elements during reallocation only when the element's move constructor is `noexcept`?
Options
- 1Moving is illegal unless the move constructor is noexcept, as required for all standard containers.
- 2Because noexcept on the move constructor enables the compiler to apply copy elision during reallocation.
- 3Because it uses std::move_if_noexcept, which itself throws when the move constructor may throw.
- 4If a move could throw mid-reallocation the strong guarantee would be lost, so it copies instead to stay transactional.
Think you can answer under pressure?
Get matched and answer live questions in 3-minute 1v1 battles. Elo ranking, badge tiers and bragging rights on the line.