1+++
2title = "`void swap(basic_result &)`"
3description = "Swap one basic_result with another, with the strong guarantee. Noexcept propagating."
4categories = ["modifiers"]
5weight = 900
6+++
7
8Swap one basic_result with another, with the strong guarantee. Constexpr if move constructors and move assignments of `value_type` and `error_type` are noexcept.
9
10*Requires*: Always available.
11
12*Complexity*: If the move constructor and move assignment for `value_type` and `error_type` are noexcept, the complexity is the same as for the `swap()` implementations of the `value_type` and `error_type`. Otherwise, complexity is not preserved, as {{% api "strong_swap(bool &all_good, T &a, T &b)" %}} is used instead of `swap()`. This function defaults to using one move construction and two assignments, and it will attempt extra move assignments in order to restore the state upon entry if a failure occurs.
13
14*Guarantees*: If an exception is thrown during the swap operation, the state of both operands on entry is attempted to be restored, in order to implement the strong guarantee. If that too fails, the flag bits are forced to something consistent such that there can be no simultaneously valued and errored state, or valueless and errorless. The flag {{% api "has_lost_consistency()" %}} becomes true for both operands, which are now likely in an inconsistent state.
15