Skip to content

Commit fd0b63a

Browse files
authored
Add has_error() to expected (#171)
1 parent 1daa718 commit fd0b63a

File tree

2 files changed

+268
-22
lines changed

2 files changed

+268
-22
lines changed

include/pfn/expected.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,7 @@ template <class T, class E> class expected {
674674
constexpr T &&operator*() && noexcept { return ::std::move(*(this->operator->())); }
675675
constexpr explicit operator bool() const noexcept { return set_; }
676676
constexpr bool has_value() const noexcept { return set_; }
677+
constexpr bool has_error() const noexcept { return !set_; }
677678
constexpr T const &value() const &
678679
{
679680
static_assert(::std::is_copy_constructible_v<E>);
@@ -1248,6 +1249,7 @@ class expected<T, E> {
12481249
// [expected.void.obs], observers
12491250
constexpr explicit operator bool() const noexcept { return set_; }
12501251
constexpr bool has_value() const noexcept { return set_; }
1252+
constexpr bool has_error() const noexcept { return !set_; }
12511253
constexpr void operator*() const noexcept { ASSERT(set_); }
12521254
constexpr void value() const &
12531255
{

0 commit comments

Comments
 (0)