boost::capy::results
Bundles an error code with optional payload values, exposed via the tuple protocol.
Synopsis
Declared in <boost/capy/results.hpp>
template<class... Ts>
using results = std::tuple<std::error_code, Ts...>;
Description
This alias provides a unified result type for async operations, always containing a std::error_code plus optional additional values. Because it is a std::tuple, results interoperate with the entire standard tuple API: structured bindings, std::tie, std::apply, std::get, std::tuple_cat, comparisons, and tuple assignment.
Example
capy::task<> discard_first_chunk( capy::any_read_stream& s, capy::mutable_buffer buf )
{
auto [ec, n] = co_await s.read_some(buf);
if (ec)
co_return; // error: n's meaning here is defined by read_some
}
std::tie rebinds into existing variables without introducing new bindings:
capy::task<> read_into_locals( capy::any_read_stream& s, capy::mutable_buffer buf )
{
std::error_code ec;
std::size_t n = 0;
std::tie(ec, n) = co_await s.read_some(buf);
}
|
Whether the payload is meaningful when the error code is set is defined by the operation that produced the result. Many I/O operations report a meaningful partial result alongside the error (for example, the number of bytes transferred before the condition, as with EOF). Others leave it unspecified. |
Template Parameters
Name |
Description |
Ts |
Ordered payload types following the leading |
Created with MrDocs