|
Common System 0.2.0
Common interfaces and patterns for system integration
|
Result type for error handling with member function support. More...
#include <core.h>

Public Types | |
| using | value_type = T |
| Type alias for the contained value type (for concept compatibility) | |
| using | error_type = error_info |
| Type alias for the error type. | |
Public Member Functions | |
| Result (const T &value) | |
| Result (T &&value) | |
| Result (const error_info &error) | |
| Result (error_info &&error) | |
| Result (const typed_error_code &ec) | |
| Construct from category-based typed_error_code. | |
| Result ()=delete | |
| Default constructor is deleted to enforce explicit initialization. | |
| Result (const Result &)=default | |
| Result (Result &&)=default | |
| Result & | operator= (const Result &)=default |
| Result & | operator= (Result &&)=default |
| bool | is_ok () const |
| Check if result contains a successful value. | |
| bool | is_err () const |
| Check if result contains an error. | |
| const T & | unwrap () const |
| Get value from result (throws if error) | |
| T & | unwrap () |
| Get mutable value from result (throws if error) | |
| T | unwrap_or (T default_value) const |
| Get value or return default. | |
| T | value_or (T default_value) const |
| Get value or return default (C++23 std::expected compatible) | |
| const T & | value () const |
| Get value reference (const) | |
| T & | value () |
| Get value reference (mutable) | |
| const error_info & | error () const |
| Get error reference. | |
| template<typename F > | |
| auto | map (F &&func) const -> Result< decltype(func(std::declval< T >()))> |
| Map a function over a successful result. | |
| template<typename F > | |
| auto | and_then (F &&func) const -> decltype(func(std::declval< T >())) |
| Map a function that returns a Result (flatMap/bind) | |
| template<typename F > | |
| Result< T > | or_else (F &&func) const |
| Provide alternative value if error. | |
| Result (const T &value) | |
| Result (T &&value) | |
| Result (const error_info &error) | |
| Result (error_info &&error) | |
| Result ()=delete | |
| Result (const Result &)=default | |
| Result (Result &&)=default | |
| Result & | operator= (const Result &)=default |
| Result & | operator= (Result &&)=default |
| bool | is_ok () const |
| bool | is_err () const |
| const T & | unwrap () const |
| T & | unwrap () |
| T | unwrap_or (T default_value) const |
| T | value_or (T default_value) const |
| const T & | value () const |
| T & | value () |
| const error_info & | error () const |
| template<typename F > | |
| auto | map (F &&func) const -> Result< decltype(func(std::declval< T >()))> |
| template<typename F > | |
| auto | and_then (F &&func) const -> decltype(func(std::declval< T >())) |
| template<typename F > | |
| Result< T > | or_else (F &&func) const |
Static Public Member Functions | |
| template<typename U = T> | |
| static Result< T > | ok (U &&value) |
| Create a successful result with value (static factory) | |
| static Result< T > | err (const error_info &error) |
| Create an error result from error_info (static factory) | |
| static Result< T > | err (error_info &&error) |
| Create an error result from error_info (static factory, move) | |
| static Result< T > | err (int code, const std::string &message, const std::string &module="") |
| Create an error result with code and message (static factory) | |
| static Result< T > | err (const typed_error_code &ec) |
| Create an error result from category-based typed_error_code (static factory) | |
| static Result< T > | uninitialized () |
| Create an explicitly uninitialized result (use with caution) | |
| template<typename U = T> | |
| static Result< T > | ok (U &&value) |
| static Result< T > | err (const error_info &error) |
| static Result< T > | err (error_info &&error) |
| static Result< T > | err (int code, const std::string &message, const std::string &module="") |
| static Result< T > | uninitialized () |
Private Attributes | |
| std::optional< T > | value_ |
| std::optional< error_info > | error_ |
Result type for error handling with member function support.
A Result<T> can be in one of two states:
This provides a type-safe way to handle errors without exceptions.
IMPORTANT: Default-constructed Results are deleted to enforce explicit initialization. For explicit construction, use factory methods Result<T>::ok() and Result<T>::err().
Thread Safety Note:
A Result<T> can be in one of two states:
| T | The type of the successful value |
|
export |
|
export |
|
inline |
Definition at line 182 of file core.h.
|
inline |
|
inline |
Definition at line 184 of file core.h.
|
inline |
|
inline |
Construct from category-based typed_error_code.
Enables seamless integration with the decentralized error category system. The typed_error_code is converted to error_info internally.
| ec | Category-based typed error code |
|
delete |
Default constructor is deleted to enforce explicit initialization.
This forces developers to explicitly use factory methods.
Migration: Use Result<T>::ok() for successful results or Result<T>::err() for error results. For cases requiring a default error state, use Result<T>::uninitialized() factory method.
Referenced by kcenon::common::Result< T >::err(), kcenon::common::Result< T >::err(), kcenon::common::Result< T >::err(), kcenon::common::Result< T >::err(), kcenon::common::Result< T >::map(), kcenon::common::Result< T >::ok(), and kcenon::common::Result< T >::uninitialized().

|
default |
|
default |
|
inlineexport |
|
inlineexport |
|
inlineexport |
|
inlineexport |
|
exportdelete |
|
exportdefault |
|
exportdefault |
|
inline |
Map a function that returns a Result (flatMap/bind)
Definition at line 430 of file core.h.
References kcenon::common::Result< T >::error_, kcenon::common::Result< T >::is_err(), kcenon::common::Result< T >::is_ok(), and kcenon::common::Result< T >::value_.

|
inlineexport |
Definition at line 306 of file core.cppm.
References kcenon::common::Result< T >::error_, kcenon::common::Result< T >::is_err(), kcenon::common::Result< T >::is_ok(), and kcenon::common::Result< T >::value_.

|
inlinestatic |
Create an error result from error_info (static factory)
| error | The error information |
Definition at line 232 of file core.h.
References kcenon::common::Result< T >::error(), and kcenon::common::Result< T >::Result().
Referenced by kcenon::common::enum_from_string(), kcenon::common::Result< T >::unwrap(), and kcenon::common::Result< T >::unwrap().


|
inlinestaticexport |
Definition at line 193 of file core.cppm.
References kcenon::common::Result< T >::error(), and kcenon::common::Result< T >::Result().

|
inlinestatic |
Create an error result from category-based typed_error_code (static factory)
Enables seamless integration with the decentralized error category system.
| ec | Category-based typed error code |
Example usage:
Definition at line 271 of file core.h.
References kcenon::common::Result< T >::Result().

|
inlinestatic |
Create an error result from error_info (static factory, move)
| error | The error information |
Definition at line 241 of file core.h.
References kcenon::common::Result< T >::error(), and kcenon::common::Result< T >::Result().

|
inlinestaticexport |
Definition at line 197 of file core.cppm.
References kcenon::common::Result< T >::error(), and kcenon::common::Result< T >::Result().

|
inlinestatic |
Create an error result with code and message (static factory)
| code | Error code |
| message | Error message |
| module | Optional module name |
Definition at line 252 of file core.h.
References kcenon::common::Result< T >::Result().

|
inlinestaticexport |
Definition at line 201 of file core.cppm.
References kcenon::common::Result< T >::Result().

|
inline |
Get error reference.
Definition at line 405 of file core.h.
References kcenon::common::Result< T >::error_.
Referenced by kcenon::common::Result< T >::err(), kcenon::common::Result< T >::err(), mock_executor::execute(), mock_executor::execute_delayed(), and main().

|
inlineexport |
Definition at line 288 of file core.cppm.
References kcenon::common::Result< T >::error_.
|
inline |
Check if result contains an error.
Definition at line 297 of file core.h.
References kcenon::common::Result< T >::error_.
Referenced by kcenon::common::Result< T >::and_then(), kcenon::common::Result< T >::map(), kcenon::common::Result< T >::or_else(), kcenon::common::Result< T >::unwrap(), and kcenon::common::Result< T >::unwrap().

|
inlineexport |
Definition at line 213 of file core.cppm.
References kcenon::common::Result< T >::error_.
|
inline |
Check if result contains a successful value.
Definition at line 290 of file core.h.
References kcenon::common::Result< T >::value_.
Referenced by kcenon::common::Result< T >::and_then(), kcenon::common::Result< T >::map(), kcenon::common::Result< T >::or_else(), and kcenon::common::Result< T >::unwrap_or().

|
inlineexport |
Definition at line 209 of file core.cppm.
References kcenon::common::Result< T >::value_.
|
inline |
Map a function over a successful result.
Definition at line 413 of file core.h.
References kcenon::common::Result< T >::error_, kcenon::common::Result< T >::is_err(), kcenon::common::Result< T >::is_ok(), kcenon::common::Result< T >::Result(), kcenon::common::Result< T >::uninitialized(), and kcenon::common::Result< T >::value_.

|
inlineexport |
Definition at line 293 of file core.cppm.
References kcenon::common::Result< T >::error_, kcenon::common::Result< T >::is_err(), kcenon::common::Result< T >::is_ok(), kcenon::common::Result< T >::Result(), kcenon::common::Result< T >::uninitialized(), and kcenon::common::Result< T >::value_.

|
inlinestatic |
Create a successful result with value (static factory)
| value | The value to wrap in Result (forwarded) |
Uses perfect forwarding to avoid ambiguity and support both lvalues and rvalues efficiently.
Definition at line 223 of file core.h.
References kcenon::common::Result< T >::Result(), and kcenon::common::Result< T >::value().
Referenced by kcenon::common::config::cli_config_parser::apply_override(), kcenon::common::di::service_container::check_already_registered(), kcenon::common::di::service_container::check_frozen_for_registration(), kcenon::common::di::service_container::clear(), kcenon::common::di::service_scope::clear(), kcenon::common::config::config_watcher::do_reload(), kcenon::common::enum_from_string(), kcenon::common::interfaces::NullLogger::flush(), kcenon::common::bootstrap::SystemBootstrapper::initialize(), kcenon::common::di::unified_bootstrapper::initialize(), kcenon::common::config::config_loader::load_from_env(), kcenon::common::config::config_loader::load_from_string(), kcenon::common::config::cli_config_parser::load_with_cli_overrides(), kcenon::common::interfaces::NullLogger::log(), kcenon::common::interfaces::NullLogger::log(), kcenon::common::interfaces::NullLogger::log(), kcenon::common::logging::log(), kcenon::common::logging::log(), kcenon::common::logging::log(), kcenon::common::config::config_loader::merge_env_overrides(), kcenon::common::config::cli_config_parser::parse(), kcenon::common::di::unified_bootstrapper::register_core_services(), kcenon::common::interfaces::GlobalLoggerRegistry::register_factory(), kcenon::common::di::service_container::register_factory_internal(), kcenon::common::di::service_container::register_instance_internal(), kcenon::common::interfaces::GlobalLoggerRegistry::register_logger(), kcenon::common::bootstrap::SystemBootstrapper::register_loggers(), kcenon::common::di::unified_bootstrapper::register_module(), kcenon::common::di::unified_bootstrapper::register_optional_services(), kcenon::common::di::unified_bootstrapper::register_shutdown_hook(), kcenon::common::config::config_watcher::rollback(), kcenon::common::interfaces::GlobalLoggerRegistry::set_default_factory(), kcenon::common::interfaces::GlobalLoggerRegistry::set_default_logger(), kcenon::common::interfaces::NullLogger::set_level(), kcenon::common::di::unified_bootstrapper::shutdown(), kcenon::common::config::config_watcher::start(), kcenon::common::di::service_container::unregister_internal(), kcenon::common::interfaces::GlobalLoggerRegistry::unregister_logger(), kcenon::common::di::unified_bootstrapper::unregister_module(), kcenon::common::di::unified_bootstrapper::unregister_shutdown_hook(), and kcenon::common::config::config_loader::validate().


|
inlinestaticexport |
Definition at line 189 of file core.cppm.
References kcenon::common::Result< T >::Result(), and kcenon::common::Result< T >::value().

|
default |
|
exportdefault |
|
default |
|
exportdefault |
|
inline |
Provide alternative value if error.
Definition at line 447 of file core.h.
References kcenon::common::Result< T >::error_, kcenon::common::Result< T >::is_err(), and kcenon::common::Result< T >::is_ok().

|
inlineexport |
Definition at line 319 of file core.cppm.
References kcenon::common::Result< T >::error_, kcenon::common::Result< T >::is_err(), and kcenon::common::Result< T >::is_ok().

|
inlinestatic |
Create an explicitly uninitialized result (use with caution)
This factory method is provided for cases where an uninitialized state is explicitly required (e.g., delayed initialization, placeholder values). Use sparingly and prefer explicit initialization with ok() or err().
Definition at line 283 of file core.h.
References kcenon::common::Result< T >::Result().
Referenced by kcenon::common::Result< T >::map().


|
inlinestaticexport |
Definition at line 205 of file core.cppm.
References kcenon::common::Result< T >::Result().

|
inline |
Get mutable value from result (throws if error)
| std::runtime_error | if result contains error |
Definition at line 360 of file core.h.
References kcenon::common::Result< T >::err(), kcenon::common::Result< T >::error_, kcenon::common::Result< T >::is_err(), and kcenon::common::Result< T >::value_.

|
inlineexport |
Definition at line 260 of file core.cppm.
References kcenon::common::Result< T >::err(), kcenon::common::Result< T >::error_, kcenon::common::Result< T >::is_err(), and kcenon::common::Result< T >::value_.

|
inline |
Get value from result (throws if error)
| std::runtime_error | if result contains error |
Definition at line 326 of file core.h.
References kcenon::common::Result< T >::err(), kcenon::common::Result< T >::error_, kcenon::common::Result< T >::is_err(), and kcenon::common::Result< T >::value_.

|
inlineexport |
Definition at line 252 of file core.cppm.
References kcenon::common::Result< T >::err(), kcenon::common::Result< T >::error_, kcenon::common::Result< T >::is_err(), and kcenon::common::Result< T >::value_.

|
inline |
Get value or return default.
Definition at line 372 of file core.h.
References kcenon::common::Result< T >::is_ok(), and kcenon::common::Result< T >::value_.
Referenced by safe_unwrap(), and kcenon::common::Result< T >::value_or().


|
inlineexport |
Definition at line 269 of file core.cppm.
References kcenon::common::Result< T >::is_ok(), and kcenon::common::Result< T >::value_.

|
inline |
Get value reference (mutable)
Definition at line 398 of file core.h.
References kcenon::common::Result< T >::value_.
|
inlineexport |
Definition at line 284 of file core.cppm.
References kcenon::common::Result< T >::value_.
|
inline |
Get value reference (const)
Definition at line 391 of file core.h.
References kcenon::common::Result< T >::value_.
Referenced by kcenon::common::Result< T >::ok().

|
inlineexport |
Definition at line 280 of file core.cppm.
References kcenon::common::Result< T >::value_.
|
inline |
Get value or return default (C++23 std::expected compatible)
Alias for unwrap_or() that matches std::expected::value_or() API.
Definition at line 384 of file core.h.
References kcenon::common::Result< T >::unwrap_or().
Referenced by kcenon::common::interfaces::health_monitor::~health_monitor().


|
inlineexport |
Definition at line 276 of file core.cppm.
References kcenon::common::Result< T >::unwrap_or().

|
exportprivate |
Definition at line 178 of file core.h.
Referenced by kcenon::common::Result< T >::and_then(), kcenon::common::Result< T >::error(), kcenon::common::Result< T >::is_err(), kcenon::common::Result< T >::map(), kcenon::common::Result< T >::or_else(), kcenon::common::Result< T >::unwrap(), and kcenon::common::Result< T >::unwrap().
|
exportprivate |
Definition at line 177 of file core.h.
Referenced by kcenon::common::Result< T >::and_then(), kcenon::common::Result< T >::is_ok(), kcenon::common::Result< T >::map(), kcenon::common::Result< T >::unwrap(), kcenon::common::Result< T >::unwrap(), kcenon::common::Result< T >::unwrap_or(), kcenon::common::Result< T >::value(), and kcenon::common::Result< T >::value().