Std::move if noexcept
lastmod 2026-11-10created 2015-09-132 edits
std::move_if_noexcept is a C++11 utility function template that returns an rvalue reference only when the type's move constructor does not throw exceptions (noexcept), and otherwise returns an lvalue reference so that a copy is made. Because an exception thrown partway through a move can leave both the source and the destination incomplete, it is used in code that needs the strong exception guarantee, such as std::vector reallocation. This is why marking move constructors noexcept matters.