11#include <system_error>
61 const std::string &
message()
const {
return message_; }
95 : data_(
Error(code, std::
move(message))) {}
101 bool is_ok()
const {
return std::holds_alternative<T>(data_); }
107 bool is_error()
const {
return std::holds_alternative<Error>(data_); }
121 T &&
value() && {
return std::get<T>(std::move(data_)); }
128 const Error &
error()
const {
return std::get<Error>(data_); }
154 std::variant<T, Error> data_;
179 : error_(
Error(code, std::
move(message))) {}
185 bool is_ok()
const {
return !error_.has_value(); }
191 bool is_error()
const {
return error_.has_value(); }
205 std::optional<Error> error_;
242 return Result<T>(code, std::move(message));
Error information with context.
const std::string & message() const
Get error message.
ErrorCode code() const
Get error code.
std::string description() const
Get full error description.
bool is_ok() const
Check if result is success.
Result(ErrorCode code, std::string message="")
Create error result from error code.
bool is_error() const
Check if result is error.
Result(Error error)
Create error result.
Result()
Create successful void result.
const Error & error() const
Get the error (assumes error)
Result type that can contain either a value or an error.
const T & value() const &
Get the value (assumes success)
T value_or(const T &default_value) const &
Get value or default if error.
T && value() &&
Get the value (assumes success)
bool is_ok() const
Check if result contains a value (success)
Result(ErrorCode code, std::string message="")
Create error result from error code.
Result(T value)
Create successful result with value.
bool is_error() const
Check if result contains an error.
const Error & error() const
Get the error (assumes error)
T value_or(T &&default_value) &&
Get value or default if error.
Result(Error error)
Create error result.
ErrorCode
Error codes for duvc operations.
@ InvalidValue
Property value out of range.
@ InvalidArgument
Invalid function argument.
@ DeviceBusy
Device is busy or in use.
@ PermissionDenied
Insufficient permissions.
@ Success
Operation succeeded.
@ PropertyNotSupported
Property not supported by device.
@ NotImplemented
Feature not implemented on this platform.
@ SystemError
System/platform error.
@ DeviceNotFound
Device not found or disconnected.
const char * to_string(CamProp)
Convert camera property enum to string.
Result< T > Err(Error error)
Helper to create error Result.
Result< void > Ok()
Helper to create successful void Result.