|
Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
|
A template class representing either a value or an error. More...
#include <error_handling.h>

Public Types | |
| using | value_type = T |
| using | error_type = error |
Public Member Functions | |
| result (T value) | |
| Constructs a result with a value. | |
| result (error err) | |
| Constructs a result with an error. | |
| operator bool () const noexcept | |
| Checks if the result contains a value. | |
| bool | has_value () const noexcept |
| Checks if the result contains a value. | |
| bool | is_ok () const noexcept |
| Checks if the result is successful. | |
| bool | is_error () const noexcept |
| Checks if the result contains an error. | |
| T & | value () & |
| Gets the value. | |
| const T & | value () const & |
| Gets the value. | |
| T && | value () && |
| Gets the value. | |
| error & | get_error () & |
| Gets the error. | |
| const error & | get_error () const & |
| Gets the error. | |
| error && | get_error () && |
| Gets the error. | |
| template<typename U > | |
| T | value_or (U &&default_value) const & |
| Gets the value or a default. | |
| template<typename U > | |
| T | value_or (U &&default_value) && |
| Gets the value or a default. | |
| T | value_or_throw () const & |
| Gets the value or throws an exception. | |
| T | value_or_throw () && |
| Gets the value or throws an exception. | |
| template<typename Fn > | |
| auto | map (Fn &&fn) const -> result< std::invoke_result_t< Fn, const T & > > |
| Maps the result to another type using a function. | |
| template<typename Fn > | |
| auto | and_then (Fn &&fn) const -> std::invoke_result_t< Fn, const T & > |
| Maps the result to another type using a function that returns a result. | |
Private Attributes | |
| bool | has_value_ = false |
| T | value_ {} |
| error | error_ {error_code::success, ""} |
A template class representing either a value or an error.
This class is similar to std::expected from C++23, but can be used with C++20. It holds either a value of type T or an error.
Definition at line 252 of file error_handling.h.
| using kcenon::thread::result< T >::error_type = error |
Definition at line 255 of file error_handling.h.
| using kcenon::thread::result< T >::value_type = T |
Definition at line 254 of file error_handling.h.
|
inline |
Constructs a result with a value.
| value | The value to store |
Definition at line 261 of file error_handling.h.
|
inline |
Constructs a result with an error.
| err | The error to store |
Definition at line 267 of file error_handling.h.
|
inlinenodiscard |
Maps the result to another type using a function that returns a result.
| fn | The function to apply to the value |
Definition at line 446 of file error_handling.h.
References kcenon::thread::result< T >::error_, kcenon::thread::result< T >::has_value_, and kcenon::thread::result< T >::value_.
|
inlinenodiscard |
Gets the error.
| std::runtime_error | if the result contains a value |
Definition at line 344 of file error_handling.h.
References kcenon::thread::result< T >::error_, and kcenon::thread::result< T >::has_value_.
Referenced by kcenon::thread::typed_thread_pool_builder< job_type >::build(), kcenon::thread::result_to_optional_error(), and kcenon::thread::result_to_pair().

|
inlinenodiscard |
Gets the error.
| std::runtime_error | if the result contains a value |
Definition at line 368 of file error_handling.h.
References kcenon::thread::result< T >::error_, and kcenon::thread::result< T >::has_value_.
|
inlinenodiscard |
Gets the error.
| std::runtime_error | if the result contains a value |
Definition at line 356 of file error_handling.h.
References kcenon::thread::result< T >::error_, and kcenon::thread::result< T >::has_value_.
|
inlinenodiscardnoexcept |
Checks if the result contains a value.
Definition at line 281 of file error_handling.h.
References kcenon::thread::result< T >::has_value_.
Referenced by basic_spsc_example(), kcenon::thread::aging_typed_job_queue_t< job_type >::dequeue(), kcenon::thread::aging_typed_job_queue_t< job_type >::dequeue(), mpmc_example(), performance_example(), and kcenon::thread::numa_work_stealer::steal_for().

|
inlinenodiscardnoexcept |
Checks if the result contains an error.
Definition at line 299 of file error_handling.h.
References kcenon::thread::result< T >::has_value_.
|
inlinenodiscardnoexcept |
Checks if the result is successful.
Definition at line 290 of file error_handling.h.
References kcenon::thread::result< T >::has_value_.
Referenced by adaptive_behavior_example(), kcenon::thread::backpressure_job_queue::apply_backpressure(), batch_operations_example(), kcenon::thread::adaptive_job_queue::dequeue(), kcenon::thread::aging_typed_job_queue_t< job_type >::dequeue(), different_policies_example(), kcenon::thread::protected_job::do_work(), kcenon::thread::adaptive_job_queue::enqueue(), kcenon::thread::backpressure_job_queue::enqueue_batch(), kcenon::thread::dag_scheduler::execute_job(), kcenon::thread::autoscaler::execute_scaling(), kcenon::thread::backpressure_job_queue::handle_adaptive_policy(), kcenon::thread::backpressure_job_queue::handle_block_policy(), kcenon::thread::backpressure_job_queue::handle_drop_oldest_policy(), mpmc_typed_queue_example(), kcenon::thread::dag_scheduler::on_job_failed(), optimal_selection(), performance_monitoring_example(), policy_comparison_example(), practical_use_cases(), kcenon::thread::dag_job::set_work_with_result(), kcenon::thread::adapters::thread_pool_executor_adapter::submit(), task_scheduling_example(), kcenon::thread::adaptive_job_queue::try_dequeue(), web_server_simulation(), and kcenon::thread::dag_job_builder::work_with_result().

|
inlinenodiscard |
Maps the result to another type using a function.
| fn | The function to apply to the value |
Definition at line 431 of file error_handling.h.
References kcenon::thread::result< T >::error_, kcenon::thread::result< T >::has_value_, and kcenon::thread::result< T >::value_.
|
inlineexplicitnodiscardnoexcept |
Checks if the result contains a value.
Definition at line 273 of file error_handling.h.
References kcenon::thread::result< T >::has_value_.
|
inlinenodiscard |
Gets the value.
| std::runtime_error | if the result contains an error |
Definition at line 308 of file error_handling.h.
References kcenon::thread::result< T >::has_value_, and kcenon::thread::result< T >::value_.
Referenced by adaptive_behavior_example(), basic_spsc_example(), kcenon::thread::aging_typed_job_queue_t< job_type >::dequeue(), kcenon::thread::aging_typed_job_queue_t< job_type >::dequeue(), different_policies_example(), kcenon::thread::adaptive_job_queue::migrate_to_mode(), mpmc_example(), optimal_selection(), performance_monitoring_example(), policy_comparison_example(), practical_use_cases(), kcenon::thread::result_to_pair(), kcenon::thread::dag_job::set_work_with_result(), kcenon::thread::numa_work_stealer::steal_for(), task_scheduling_example(), kcenon::thread::aging_typed_job_queue_t< job_type >::try_dequeue_from_priority(), web_server_simulation(), and kcenon::thread::dag_job_builder::work_with_result().

|
inlinenodiscard |
Gets the value.
| std::runtime_error | if the result contains an error |
Definition at line 332 of file error_handling.h.
References kcenon::thread::result< T >::has_value_, and kcenon::thread::result< T >::value_.
|
inlinenodiscard |
Gets the value.
| std::runtime_error | if the result contains an error |
Definition at line 320 of file error_handling.h.
References kcenon::thread::result< T >::has_value_, and kcenon::thread::result< T >::value_.
|
inlinenodiscard |
Gets the value or a default.
| default_value | The value to return if the result contains an error |
Definition at line 394 of file error_handling.h.
References kcenon::thread::result< T >::has_value_, and kcenon::thread::result< T >::value_.
|
inlinenodiscard |
Gets the value or a default.
| default_value | The value to return if the result contains an error |
Definition at line 381 of file error_handling.h.
References kcenon::thread::result< T >::has_value_, and kcenon::thread::result< T >::value_.
|
inlinenodiscard |
Gets the value or throws an exception.
| std::runtime_error | with the error message if the result contains an error |
Definition at line 418 of file error_handling.h.
References kcenon::thread::result< T >::error_, kcenon::thread::result< T >::has_value_, kcenon::thread::error::to_string(), and kcenon::thread::result< T >::value_.

|
inlinenodiscard |
Gets the value or throws an exception.
| std::runtime_error | with the error message if the result contains an error |
Definition at line 406 of file error_handling.h.
References kcenon::thread::result< T >::error_, kcenon::thread::result< T >::has_value_, kcenon::thread::error::to_string(), and kcenon::thread::result< T >::value_.

|
private |
Definition at line 459 of file error_handling.h.
Referenced by kcenon::thread::result< T >::and_then(), kcenon::thread::result< void >::and_then(), kcenon::thread::result< T >::get_error(), kcenon::thread::result< T >::get_error(), kcenon::thread::result< T >::get_error(), kcenon::thread::result< void >::get_error(), kcenon::thread::result< void >::get_error(), kcenon::thread::result< void >::get_error(), kcenon::thread::result< T >::map(), kcenon::thread::result< void >::map(), kcenon::thread::result< T >::value_or_throw(), kcenon::thread::result< T >::value_or_throw(), and kcenon::thread::result< void >::value_or_throw().
|
private |
Definition at line 457 of file error_handling.h.
Referenced by kcenon::thread::result< T >::and_then(), kcenon::thread::result< T >::get_error(), kcenon::thread::result< T >::get_error(), kcenon::thread::result< T >::get_error(), kcenon::thread::result< T >::has_value(), kcenon::thread::result< T >::is_error(), kcenon::thread::result< T >::is_ok(), kcenon::thread::result< T >::map(), kcenon::thread::result< T >::operator bool(), kcenon::thread::result< T >::value(), kcenon::thread::result< T >::value(), kcenon::thread::result< T >::value(), kcenon::thread::result< T >::value_or(), kcenon::thread::result< T >::value_or(), kcenon::thread::result< T >::value_or_throw(), and kcenon::thread::result< T >::value_or_throw().
|
private |
Definition at line 458 of file error_handling.h.
Referenced by kcenon::thread::result< T >::and_then(), kcenon::thread::result< T >::map(), kcenon::thread::result< T >::value(), kcenon::thread::result< T >::value(), kcenon::thread::result< T >::value(), kcenon::thread::result< T >::value_or(), kcenon::thread::result< T >::value_or(), kcenon::thread::result< T >::value_or_throw(), and kcenon::thread::result< T >::value_or_throw().