cti namespace

Declares the continuable library namespace.

The most important class is cti::continuable_base, that provides the whole functionality for continuation chaining.

The class cti::continuable_base is created through the cti::make_continuable() function which accepts a callback taking function.

Also there are following support functions available:

Namespaces

namespace transforms
The namespace transforms declares callable objects that transform any continuable_base to an object or to a continuable_base itself.

Classes

struct cancellation_result
A class which is convertible to any result and that definitely holds a default constructed exception which signals the cancellation of the asynchronous control flow.
template<typename Data, typename Annotation>
class continuable_base
The main class of the continuable library, it provides the functionality for chaining callbacks and continuations together to a unified hierarchy.
struct empty_result
A class which is convertible to any result and that definitely holds no value so the real result gets invalidated when this object is passed to it.
struct exception_arg_t
Represents the tag type that is used to disambiguate the callback operator() in order to take the exception asynchronous chain.
class exceptional_result
A class which is convertible to any result and that holds an exception which is then passed to the converted result object.
struct is_ready_arg_t
Represents the tag type that is used to query the continuation for whether it resolves the callback instantly with its arguments without having side effects.
template<typename Data, typename Hint>
class promise_base
The promise_base makes it possible to resolve an asynchronous continuable through it's result or through an error type.
template<typename... Result>
class promisify
Helper class for converting callback taking callable types into a a continuable. Various styles are supported.
template<typename... T>
class result
The result class can carry the three kinds of results an asynchronous operation possibly can return, it's implemented in a variant like data structure which is also specialized to hold arbitrary arguments.
struct unpack_arg_t
Represents the tag type that is used to unpack the result of a continuation.
template<typename Mapper = detail::asio::map_default>
struct use_continuable_t
Type used as an ASIO completion token to specify an asynchronous operation that should return a continuable_base.

Typedefs

template<typename T>
using is_continuable = detail::base::is_continuable<T>
Deduces to a true_type if the given type is a continuable_base.
template<typename... Args>
using signature_arg_t = detail::identity<Args...>
Represents the tag type that is used to specify the signature hint of a continuable_base or promise_base.
using query_arg_t = unpack_arg_t deprecated
Represents the tag type that is used to unpack the result of a continuation.
using dispatch_error_tag = exception_arg_t deprecated
Represents the tag type that is used to disambiguate the callback operator() in order to take the exception asynchronous chain.
using exception_t = detail::types::exception_t
Represents the type that is used as exception type.
using error_type = exception_t deprecated
Represents the type that is used as exception type.
template<typename T>
using plain_t = detail::types::plain_tag<T>
Represents the type that is used to disable the special meaning of types which are returned by a asynchronous result handler. See cti::plain for details.
using void_arg_t = detail::void_arg_t
A tag which represents present void values in result.
using async_traverse_visit_tag = detail::traversal::async_traverse_visit_tag
A tag which is passed to the operator() of the visitor if an element is visited synchronously through traverse_pack_async.
using async_traverse_detach_tag = detail::traversal::async_traverse_detach_tag
A tag which is passed to the operator() of the visitor if an element is visited after the traversal was detached through traverse_pack_async.
using async_traverse_complete_tag = detail::traversal::async_traverse_complete_tag
A tag which is passed to the operator() of the visitor if the asynchronous pack traversal was finished through traverse_pack_async.
template<typename T>
using async_traverse_in_place_tag = detail::traversal::async_traverse_in_place_tag<T>
A tag to identify that a mapper shall be constructed in-place from the first argument passed to traverse_pack_async.
template<typename... Args>
using continuation_capacity = detail::erasure::continuation_capacity<Args...>
Deduces to the preferred continuation capacity for a possible small functor optimization. The given capacity size is always enough to to avoid any allocation when storing a ready continuable_base.
template<typename... Args>
using continuable = continuable_base<detail::erasure::continuation<Args...>, signature_arg_t<Args...>>
Defines a non-copyable continuation type which uses the function2 backend for type erasure.
template<typename... Args>
using promise = promise_base<detail::erasure::callback<Args...>, signature_arg_t<Args...>>
Defines a non-copyable promise type which is using the function2 backend for type erasure.
using work = promise_base<detail::erasure::work, signature_arg_t<>>
Defines a non-copyable type erasure which is capable of carrying callable objects passed to executors.
using asio_error_code_t = detail::asio::error_code_t
The error code type used by your asio distribution.
using asio_basic_errors_t = detail::asio::basic_errors_t
The basic error code enum used by your asio distribution.
using asio_system_error_t = detail::asio::system_error_t
The system error type used by your asio distribution.
using use_continuable_raw_t = use_continuable_t<detail::asio::map_none>
Type used as an ASIO completion token to specify an asynchronous operation that should return a continuable_base.

Functions

template<typename... Args, typename Continuation>
auto make_continuable(Continuation&& continuation) -> auto constexpr
Creates a continuable_base from a promise/callback taking function.
template<typename... Args>
auto make_ready_continuable(Args && ... args) -> auto
Returns a continuable_base with no result which instantly resolves the promise with no values.
template<typename... Args, typename Exception>
auto make_exceptional_continuable(Exception&& exception) -> auto constexpr
Returns a continuable_base with the parameterized result which instantly resolves the promise with the given error type.
template<typename... Signature>
auto make_cancelling_continuable() -> auto
Returns a continuable_base with the parameterized result which never resolves its promise and thus cancels the asynchronous continuation chain through throwing a default constructed exception_t.
template<typename T>
auto make_plain(T&& value) -> auto
Can be used to disable the special meaning for a returned value in asynchronous handler functions.
template<typename... Args>
auto recover(Args && ... args) -> result<detail::traits::unrefcv_t<Args>...>
Can be used to recover to from a failure handler, the result handler which comes after will be called with the corresponding result.
auto rethrow(exception_t exception) -> exceptional_result
Can be used to rethrow an exception to the asynchronous continuation chain, the failure handler which comes after will be called with the corresponding exception.
auto cancel() -> cancellation_result
Can be used to cancel an asynchronous continuation chain, the next failure handler which comes after cancel will be called with a default constructed exception_t object.
auto stop() -> empty_result
Can be used to stop an asynchronous continuation chain, no handler which comes after stop was received won't be called.
template<typename... Args>
auto when_all(Args && ... args) -> auto
Connects the given arguments with an all logic. All continuables contained inside the given nested pack are invoked at once. On completion the final handler is called with the aggregated result of all continuables.
template<typename Iterator, std::enable_if_t<detail::range::is_iterator<Iterator>::value>* = nullptr>
auto when_all(Iterator begin, Iterator end) -> auto
Connects the given arguments with an all logic. The content of the iterator is moved out and converted to a temporary std::vector which is then passed to when_all.
template<typename... Args>
auto when_seq(Args && ... args) -> auto
Connects the given arguments with a sequential logic. All continuables contained inside the given nested pack are invoked one after one. On completion the final handler is called with the aggregated result of all continuables.
template<typename Iterator, std::enable_if_t<detail::range::is_iterator<Iterator>::value>* = nullptr>
auto when_seq(Iterator begin, Iterator end) -> auto
Connects the given arguments with a sequential logic. The content of the iterator is moved out and converted to a temporary std::vector which is then passed to when_seq.
template<typename... Args>
auto when_any(Args && ... args) -> auto
Connects the given arguments with an any logic. All continuables contained inside the given nested pack are invoked at once. On completion of one continuable the final handler is called with the result of the resolved continuable.
template<typename Iterator, std::enable_if_t<detail::range::is_iterator<Iterator>::value>* = nullptr>
auto when_any(Iterator begin, Iterator end) -> auto
Connects the given arguments with an any logic. The content of the iterator is moved out and converted to a temporary std::vector which is then passed to when_all.
template<template<typename, typename> class C = std::vector, typename First, typename... Args>
auto populate(First&& first, Args && ... args) -> C<std::decay_t<First>, std::allocator<std::decay_t<First>>>
Populates a homogeneous container from the given arguments. All arguments need to be convertible to the first one, by default std::vector is used as container type.
template<std::size_t I, typename... T>
auto get(result<T...>& result) -> decltype(auto)
Returns the value at position I of the given result.
template<std::size_t I, typename... T>
auto get(result<T...> const& result) -> decltype(auto)
Returns the value at position I of the given result.
template<std::size_t I, typename... T>
auto get(result<T...>&& result) -> decltype(auto)
Returns the value at position I of the given result.
template<typename... T, typename Result = result<detail::traits::unrefcv_t<T>...>>
auto make_result(T && ... values) -> Result
Creates a present result from the given values.
auto make_result(exception_arg_t, exception_t exception) -> exceptional_result
Creates an exceptional_result from the given exception.
template<typename Visitor, typename... T>
auto traverse_pack_async(Visitor&& visitor, T && ... pack) -> auto
Traverses the pack with the given visitor in an asynchronous way.
template<typename Mapper, typename... T>
auto map_pack(Mapper&& mapper, T && ... pack) -> decltype(auto)
Maps the pack with the given mapper.
template<typename... T>
auto spread_this(T && ... args) -> detail::traversal::spreading::spread_box<std::decay_t<T>...> constexpr noexcept(…)
Indicate that the result shall be spread across the parent container if possible. This can be used to create a mapper function used in map_pack that maps one element to an arbitrary count (1:n).
template<typename Mapper, typename... T>
void traverse_pack(Mapper&& mapper, T && ... pack)
Traverses the pack with the given visitor.
template<typename... Args>
auto use_continuable_ignoring(Args && ... args) -> auto noexcept
Represents a special asio completion token which treats the given asio basic error codes as success instead of failure.

Variables

use_continuable_t use_continuable constexpr
Special value for instance of use_continuable_t which performs remapping of asio error codes to align the cancellation behaviour with the library.
use_continuable_raw_t use_continuable_raw constexpr
Special value for instance of use_continuable_raw_t which doesn't perform remapping of asio error codes and rethrows the raw error code.

Typedef documentation

using cti::asio_error_code_t = detail::asio::error_code_t

The error code type used by your asio distribution.

using cti::asio_basic_errors_t = detail::asio::basic_errors_t

The basic error code enum used by your asio distribution.

using cti::asio_system_error_t = detail::asio::system_error_t

The system error type used by your asio distribution.

using cti::use_continuable_raw_t = use_continuable_t<detail::asio::map_none>

Type used as an ASIO completion token to specify an asynchronous operation that should return a continuable_base.

  • Boost 1.70 or asio 1.13.0 is required for the async initiation
  • Until boost 1.72 or asio 1.16.0 overhead through an additional type erasure is added. It is recommended to update to those versions.

The special static variable use_continuable can be appended to any (boost) asio function that accepts a callback to make it return a continuable_base.

#include <continuable/continuable.hpp>
#include <continuable/external/asio.hpp>
#include <asio.hpp>

// ...

asio::tcp::resolver resolver(...);
resolver.async_resolve("127.0.0.1", "daytime", cti::use_continuable)
  .then([](asio::udp::resolver::iterator iterator) {
    // ...
  });

The raw async completion handler token does not remap the asio error asio::error::basic_errors::operation_aborted to a default constructed exception type.

Function documentation

template<typename... Args>
auto cti::use_continuable_ignoring(Args && ... args) noexcept

Represents a special asio completion token which treats the given asio basic error codes as success instead of failure.

asio::error::basic_errors::operation_aborted is mapped as cancellation token.

Variable documentation

use_continuable_t cti::use_continuable constexpr

Special value for instance of use_continuable_t which performs remapping of asio error codes to align the cancellation behaviour with the library.

  • Boost 1.70 or asio 1.13.0 is required for the async initiation
  • Until boost 1.72 or asio 1.16.0 overhead through an additional type erasure is added. It is recommended to update to those versions.

The special static variable use_continuable can be appended to any (boost) asio function that accepts a callback to make it return a continuable_base.

#include <continuable/continuable.hpp>
#include <continuable/external/asio.hpp>
#include <asio.hpp>

// ...

asio::tcp::resolver resolver(...);
resolver.async_resolve("127.0.0.1", "daytime", cti::use_continuable)
  .then([](asio::udp::resolver::iterator iterator) {
    // ...
  });

use_continuable_raw_t cti::use_continuable_raw constexpr

Special value for instance of use_continuable_raw_t which doesn't perform remapping of asio error codes and rethrows the raw error code.

  • Boost 1.70 or asio 1.13.0 is required for the async initiation
  • Until boost 1.72 or asio 1.16.0 overhead through an additional type erasure is added. It is recommended to update to those versions.

The special static variable use_continuable can be appended to any (boost) asio function that accepts a callback to make it return a continuable_base.

#include <continuable/continuable.hpp>
#include <continuable/external/asio.hpp>
#include <asio.hpp>

// ...

asio::tcp::resolver resolver(...);
resolver.async_resolve("127.0.0.1", "daytime", cti::use_continuable)
  .then([](asio::udp::resolver::iterator iterator) {
    // ...
  });

The raw async completion handler token does not remap the asio error asio::error::basic_errors::operation_aborted to a default constructed exception type.