Specialization of result for void.
More...
#include <error_handling.h>
|
| | result () |
| | Constructs a successful void result.
|
| |
| | result (const result_void &r) |
| | Constructs a void result from a result_void.
|
| |
| | result (error err) |
| | Constructs a result with an error.
|
| |
| | operator bool () const noexcept |
| | Checks if the result is successful.
|
| |
| bool | has_value () const noexcept |
| | Checks if the result is successful.
|
| |
| bool | is_ok () const noexcept |
| | Checks if the result is successful.
|
| |
| bool | is_error () const noexcept |
| | Checks if the result contains an error.
|
| |
| error & | get_error () & |
| | Gets the error.
|
| |
| const error & | get_error () const & |
| | Gets the error.
|
| |
| error && | get_error () && |
| | Gets the error.
|
| |
| void | value_or_throw () const |
| | Throws an exception if the result contains an error.
|
| |
| template<typename Fn > |
| auto | map (Fn &&fn) const -> result< std::invoke_result_t< Fn > > |
| | Maps the result to another type using a function.
|
| |
| template<typename Fn > |
| auto | and_then (Fn &&fn) const -> std::invoke_result_t< Fn > |
| | Maps the result to another type using a function that returns a result.
|
| |
Specialization of result for void.
Definition at line 466 of file error_handling.h.
◆ error_type
◆ value_type
◆ result() [1/3]
◆ result() [2/3]
Constructs a void result from a result_void.
Definition at line 479 of file error_handling.h.
479:
success_(!r.has_error()),
error_(r.has_error() ? r.get_error() :
error{error_code::success,
""}) {}
@ error
Error events that might still allow continuation.
◆ result() [3/3]
◆ and_then()
Maps the result to another type using a function that returns a result.
- Parameters
-
| fn | The function to apply if successful |
- Returns
- A new result with the mapped value or the original error
Definition at line 588 of file error_handling.h.
588 {
589 using ResultType = std::invoke_result_t<Fn>;
590 static_assert(std::is_same_v<typename ResultType::error_type, error>, "Function must return a result with the same error type");
591
593 return std::invoke(std::forward<Fn>(fn));
594 }
595 return ResultType(
error_);
596 }
References kcenon::thread::result< T >::error_.
◆ get_error() [1/3]
Gets the error.
- Returns
- A reference to the contained error
- Exceptions
-
| std::runtime_error | if the result is successful |
Definition at line 526 of file error_handling.h.
526 {
528 throw std::runtime_error("Cannot get error from successful result");
529 }
531 }
References kcenon::thread::result< T >::error_.
◆ get_error() [2/3]
Gets the error.
- Returns
- An rvalue reference to the contained error
- Exceptions
-
| std::runtime_error | if the result is successful |
Definition at line 550 of file error_handling.h.
550 {
552 throw std::runtime_error("Cannot get error from successful result");
553 }
555 }
References kcenon::thread::result< T >::error_.
◆ get_error() [3/3]
Gets the error.
- Returns
- A const reference to the contained error
- Exceptions
-
| std::runtime_error | if the result is successful |
Definition at line 538 of file error_handling.h.
538 {
540 throw std::runtime_error("Cannot get error from successful result");
541 }
543 }
References kcenon::thread::result< T >::error_.
◆ has_value()
Checks if the result is successful.
- Returns
- true if the result is successful, false if it contains an error
Definition at line 499 of file error_handling.h.
◆ is_error()
Checks if the result contains an error.
- Returns
- true if the result contains an error, false if successful
- Note
- Added for API compatibility with common::Result
Definition at line 517 of file error_handling.h.
◆ is_ok()
Checks if the result is successful.
- Returns
- true if the result is successful, false if it contains an error
- Note
- Added for API compatibility with common::Result
Definition at line 508 of file error_handling.h.
◆ map()
Maps the result to another type using a function.
- Parameters
-
| fn | The function to apply if successful |
- Returns
- A new result with the mapped value or the original error
Definition at line 573 of file error_handling.h.
573 {
575
577 return ResultType(std::invoke(std::forward<Fn>(fn)));
578 }
579 return ResultType(
error_);
580 }
result()
Constructs a successful void result.
References kcenon::thread::result< T >::error_.
◆ operator bool()
|
|
inlineexplicitnodiscardnoexcept |
Checks if the result is successful.
- Returns
- true if the result is successful, false if it contains an error
Definition at line 491 of file error_handling.h.
◆ value_or_throw()
◆ error_
◆ success_
The documentation for this class was generated from the following file: