This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++17 status.

2748. swappable traits for optionals

Section: [optional.swap], 22.5.9 [optional.specalg] Status: C++17 Submitter: Agustín K-ballo Bergé Opened: 2016-07-19 Last modified: 2017-07-30

Priority: 0

View all issues with C++17 status.


optional didn't benefit from the wording modifications by P0185 "Adding [nothrow_]swappable traits"; as such, it suffers from LWG 2456, and does not play nice with swappable traits.

[2016-07 Chicago]

Monday: P0 - tentatively ready

Proposed resolution:

This wording is relative to N4606.

  1. Modify [optional.object.swap] as indicated:

    void swap(optional<T>& rhs) noexcept(see below);


    -4- Remarks: The expression inside noexcept is equivalent to:

    is_nothrow_move_constructible_v<T> && is_nothrow_swappable_v<T>noexcept(swap(declval<T&>(), declval<T&>()))
  2. Modify 22.5.9 [optional.specalg] as indicated:

    template <class T> void swap(optional<T>& x, optional<T>& y) noexcept(noexcept(x.swap(y)));

    -1- Effects: Calls x.swap(y).

    -?- Remarks: This function shall not participate in overload resolution unless is_move_constructible_v<T> is true and is_swappable_v<T> is true.