What does std::move_if_noexcept select, and how can it help generic code preserve exception guarantees?
Show answer and explanation
std::move_if_noexcept returns an rvalue reference when T is nothrow move-constructible or is not copy-constructible; otherwise it returns a const lvalue reference so overload resolution can select copying. Containers can use this choice while relocating elements: if copying exists and a move might throw after modifying the source, copying is often the path that preserves the original range on failure. The utility does not perform construction, guarantee that a copy cannot throw, or repair a dishonest noexcept declaration; the receiving operation and surrounding rollback design still determine the actual guarantee.
std::move_if_noexcept returns an rvalue reference when T is nothrow move-constructible or is not copy-constructible; otherwise it returns a const lvalue reference so overload resolution can select copying. Containers can use this choice while relocating elements: if copying exists and a move might throw after modifying the source, copying is often the path that preserves the original range on failure. The utility does not perform construction, guarantee that a copy cannot throw, or repair a dishonest noexcept declaration; the receiving operation and surrounding rollback design still determine the actual guarantee.
Connect the conclusion directly to the type, lifetime, ownership, overload-resolution rule, or library contract present in the question. State implementation dependence or a violated precondition explicitly instead of merely guessing output.