diff options
| author | levlam <levlam@telegram.org> | 2025-03-20 16:21:15 +0300 |
|---|---|---|
| committer | levlam <levlam@telegram.org> | 2025-03-20 16:21:15 +0300 |
| commit | 4a2acbe127666d4bfff832d175ef602b42a0b67b (patch) | |
| tree | b1ba712c4d3172f2b56884b1d1f327f4d6bb90e2 /tdutils | |
| parent | 82689a2c6a53c7ee368da03b313944beb18af0c2 (diff) | |
Add Result logging and comparison operators.
Diffstat (limited to 'tdutils')
| -rw-r--r-- | tdutils/td/utils/Status.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tdutils/td/utils/Status.h b/tdutils/td/utils/Status.h index 8a976243f..f62318a01 100644 --- a/tdutils/td/utils/Status.h +++ b/tdutils/td/utils/Status.h @@ -604,4 +604,22 @@ inline StringBuilder &operator<<(StringBuilder &string_builder, const Status &st return status.print(string_builder); } +template <class T> +StringBuilder &operator<<(StringBuilder &sb, const Result<T> &result) { + if (result.is_ok()) { + return sb << "Ok{" << result.ok() << '}'; + } + return sb << result.error(); +} + +template <class T, class S> +bool operator==(const S &a, const Result<T> &b) { + return b.is_ok() && a == b.ok(); +} + +template <class T, class S> +bool operator==(const Result<S> &a, const T &b) { + return a.is_ok() && a.ok() == b; +} + } // namespace td |
