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

Commit 4adfde41 authored by Bernie Innocenti's avatar Bernie Innocenti
Browse files

Add android::base::expected::ok()

This is an alias for has_value() which is meant to be more concise, yet
more explicit than the conversions to bool.

Leave operator bool() in place for now: due to the large number of
users, removal of operator bool() needs to be broken up into incremental
stages.

Test: cd system/core && atest
Test: m
Change-Id: Ib1eb00f47d3c0f2229bb176b62687463b834f280
parent 07e74d65
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -331,6 +331,7 @@ class _NODISCARD_ expected {

  constexpr explicit operator bool() const noexcept { return has_value(); }
  constexpr bool has_value() const noexcept { return var_.index() == 0; }
  constexpr bool ok() const noexcept { return has_value(); }

  constexpr const T& value() const& { return std::get<T>(var_); }
  constexpr T& value() & { return std::get<T>(var_); }
@@ -557,6 +558,7 @@ class _NODISCARD_ expected<void, E> {
  // observers
  constexpr explicit operator bool() const noexcept { return has_value(); }
  constexpr bool has_value() const noexcept { return var_.index() == 0; }
  constexpr bool ok() const noexcept { return has_value(); }

  constexpr void value() const& { if (!has_value()) std::get<0>(var_); }