co_usb
Loading...
Searching...
No Matches
co_usb::detail::as_optional_t Struct Reference

Error protocol signaling error into a given error code reference and returning an optional. More...

#include <error_protocol.hpp>

Public Types

template<typename ValTy >
using return_type = std::optional< ValTy >
 

Public Member Functions

constexpr as_optional_t (std::error_code &ec) noexcept
 
template<typename U >
auto with_error (std::error_code ec) noexcept -> return_type< U >
 Signals error to stored error code reference.
 
template<typename U , typename... Args>
auto with_success (Args &&...args) noexcept(std::is_nothrow_constructible_v< U, Args... >) -> return_type< U >
 Signals success via returned optional.
 

Detailed Description

Error protocol signaling error into a given error code reference and returning an optional.

On error, assigns the given error code to a stored error code reference and returns a nullopt. On success, clears error code by refernce and returns an optional with a success value.

Note
with_error is noexcept. with_success is noexcept if chosen ctor is noexcept.

Member Typedef Documentation

◆ return_type

template<typename ValTy >
using co_usb::detail::as_optional_t::return_type = std::optional<ValTy>

Constructor & Destructor Documentation

◆ as_optional_t()

constexpr co_usb::detail::as_optional_t::as_optional_t ( std::error_code &  ec)
inlineexplicitconstexprnoexcept

Member Function Documentation

◆ with_error()

template<typename U >
auto co_usb::detail::as_optional_t::with_error ( std::error_code  ec) -> return_type<U>
inlinenoexcept

Signals error to stored error code reference.

Returns
std::nullopt.

◆ with_success()

template<typename U , typename... Args>
auto co_usb::detail::as_optional_t::with_success ( Args &&...  args) -> return_type<U>
inlinenoexcept

Signals success via returned optional.

Returns
std::optional with constructed result.

The documentation for this struct was generated from the following file: