Skip to content

Commit

Permalink
Allow ADL for swapping Optional values (#4569)
Browse files Browse the repository at this point in the history
Some types support being swapped but may not have declared their
std::swap overloads when Poco/Optional.h is first included. This is the
case for instance with

    #include <Poco/Optional.h>
    #include <array>

    using Problematic = Poco::Optional<std::array<int, 42> >;

With an unqualified call to swap, preceded by using std::swap, we allow
argument-dependent lookup to find suitable implementations of swap.
  • Loading branch information
joukewitteveen committed Jun 17, 2024
1 parent c6249d9 commit e00b4de
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Foundation/include/Poco/Optional.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ class Optional

void swap(Optional& other) noexcept
{
std::swap(_value, other._value);
std::swap(_isSpecified, other._isSpecified);
using std::swap;
swap(_value, other._value);
swap(_isSpecified, other._isSpecified);
}

const C& value() const
Expand Down

0 comments on commit e00b4de

Please sign in to comment.