Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 820333dc authored by Tom Cherry's avatar Tom Cherry
Browse files

Add noexcept to missing places in expected.h

These move and assignment operations are conditionally noexcept, so
add that to their definitions.  This is a performance issue as well as
correctness, since std containers will copy instead of move during
resize if these operations are not noexcept.

Test: build
Change-Id: I148f7eb3489e7f1dd68cc0fb0e555b56470e42da
parent e05c799c
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -256,7 +256,8 @@ class _NODISCARD_ expected {
  expected& operator=(const expected& rhs) = default;

  // Note for SFNAIE above applies to here as well
  expected& operator=(expected&& rhs) = default;
  expected& operator=(expected&& rhs) noexcept(
      std::is_nothrow_move_assignable_v<T>&& std::is_nothrow_move_assignable_v<E>) = default;

  template <class U = T _ENABLE_IF(
                !std::is_void_v<T> &&
@@ -542,7 +543,7 @@ class _NODISCARD_ expected<void, E> {
  expected& operator=(const expected& rhs) = default;

  // Note for SFNAIE above applies to here as well
  expected& operator=(expected&& rhs) = default;
  expected& operator=(expected&& rhs) noexcept(std::is_nothrow_move_assignable_v<E>) = default;

  template<class G = E>
  expected& operator=(const unexpected<G>& rhs) {
@@ -633,7 +634,7 @@ class unexpected {
 public:
  // constructors
  constexpr unexpected(const unexpected&) = default;
  constexpr unexpected(unexpected&&) = default;
  constexpr unexpected(unexpected&&) noexcept(std::is_nothrow_move_constructible_v<E>) = default;

  template <class Err = E _ENABLE_IF(
                std::is_constructible_v<E, Err> &&
@@ -709,7 +710,8 @@ class unexpected {

  // assignment
  constexpr unexpected& operator=(const unexpected&) = default;
  constexpr unexpected& operator=(unexpected&&) = default;
  constexpr unexpected& operator=(unexpected&&) noexcept(std::is_nothrow_move_assignable_v<E>) =
      default;
  template<class Err = E>
  constexpr unexpected& operator=(const unexpected<Err>& rhs) {
    val_ = rhs.value();