stlab 2.3.0
Modern, modular C++ algorithms, data structures, and concurrency primitives
Loading...
Searching...
No Matches
stlab Namespace Reference

Classes

class  sender
class  receiver
 Receiving end of a CSP channel. More...
class  channel_error
 Exception type for channel usage errors (broken channel, process already running, etc.). More...
struct  identity
struct  result_of_
struct  result_of_< R(Args...)>
struct  first_
struct  argument_of
struct  argument_of< R(Arg)>
struct  unordered_t
 Merge strategy for merge_channel: invoke the process in arbitrary order as values arrive. More...
struct  round_robin_t
 Merge strategy for merge_channel: round-robin among upstream senders. More...
struct  zip_with_t
 Merge strategy for merge_channel / zip_with: wait for one value from each upstream, then invoke with the full argument set. More...
struct  buffer_size
 Per-process input queue capacity for flow control (combine with a process via operator&). More...
class  sender< T, enable_if_copyable< T > >
 Sending end of a CSP channel (copyable T). More...
class  sender< T, enable_if_not_copyable< T > >
 Sending end of a CSP channel (move-only T; not copyable). More...
struct  function_process
 Adapts a std::function into a channel process with await / yield / state. More...
struct  function_process< R(Args...)>
 Function-object process: binds arguments in await, runs the call in yield. More...
struct  executor
 Wraps an executor_t for use with operator&. More...
struct  executor_task_pair
 Executor plus callable, produced by executor & f (used by futures and channels). More...
struct  void_to_monostate
 Maps void to std::monostate for uniform future result storage; other types unchanged. More...
class  future_error
 Exception thrown when a future-related contract is violated (e.g. broken_promise, no_state). More...
class  packaged_task
 Invocable that completes a future when called with arguments of type Args...; created by package(). More...
class  future
 One-shot asynchronous result: holds a value or exception produced by a promise or packaged_task. More...
class  future< T, enable_if_copyable< void_to_monostate_t< T > > >
 Consumer side of a one-shot result (copyable T). More...
class  future< T, enable_if_not_copyable< void_to_monostate_t< T > > >
 Consumer side of a one-shot result (non-copyable T). Use get_ready() or get_try(); then/recover only on rvalue. More...
struct  make_when_any
 Helper to implement when_any for result type T. More...
struct  make_when_any< void >
 Helper to implement when_any for void results. More...
class  progress_tracker
 Tracks how many wrapped tasks are in flight and how many have completed. More...
class  serial_queue_t
 Executor wrapper that runs enqueued tasks serially on top of e. More...
class  task_
 Type-erased, move-only callable with signature R(Args...) (or noexcept variant). More...
struct  noexcept_deducer
struct  noexcept_deducer< T, R(Args...)>
struct  noexcept_deducer< T, R(Args...) noexcept >
struct  bool_pack
struct  smart_test
 Trait adapter; specialize for types where std::is_copy_constructible is wrong. More...
struct  voider
struct  nonesuch
struct  detector
struct  detector< Default, void_t< Op< Args... > >, Op, Args... >
class  placeholder
struct  remove_placeholder
struct  child_iterator
 Iterator over the child sequence of a node: adapts a fullorder iterator to visit only immediate children (skipping descendants). More...
struct  edge_iterator
 Fullorder iterator restricted to a single edge kind: visits only leading or trailing positions (e.g. preorder vs. postorder when Edge is fixed). More...
struct  filter_fullorder_iterator
 Fullorder iterator that visits only positions whose values satisfy predicate P (skipping others by advancing through the underlying fullorder sequence). More...
struct  reverse_fullorder_iterator
 Reverses the direction of a fullorder walk while preserving edge semantics (bidirectional). More...
struct  depth_fullorder_iterator
 Fullorder iterator that tracks depth in the tree as it advances or retreats. More...
class  child_adaptor
 Presents the children of a node (given by a fullorder iterator into forest) as a small sequence-like interface: front / back / push_front / push_back / pop_front / pop_back. More...
class  forest
 Hierarchical, node-based container: a forest (ordered sequence of trees) with fullorder iterators and child views. More...
struct  forest_range
 Half-open range [begin, end) of forest iterators; used by child_range, preorder_range, etc. More...
struct  unwrap_reference
 Type alias: T, or the referent type if T is std::reference_wrapper<U>. More...
struct  unwrap_reference< std::reference_wrapper< T > >
struct  is_reference_wrapper
struct  is_reference_wrapper< std::reference_wrapper< T > >
struct  annotate_counters
 Shared counters for annotate special-member and comparison instrumentation. More...
struct  annotate
 Test type that counts special-member and comparison operations via annotate_counters. More...
struct  regular
 Regular type that logs lifetime and comparison events to std::cout. More...
class  move_only
 Move-only polymorphic test type with equality comparison. More...
struct  index_sequence_cat
struct  index_sequence_cat< std::index_sequence< N1... >, std::index_sequence< N2... > >
struct  index_sequence_to_array
struct  index_sequence_to_array< std::index_sequence< N... > >
struct  index_sequence_transform
struct  index_sequence_transform< Seq, F, Index, 0 >
struct  index_sequence_transform< Seq, F, Index, 1 >

Concepts

concept  forward_node_iterator

Typedefs

using process_state_scheduled
 process_state plus a deadline returned from process::state().
template<typename F>
using result_of_t_
template<typename... T>
using first_t
template<typename T>
using argument_of_t
using executor_t
 Type-erased executor: accepts a void() noexcept task.
template<class T>
using void_to_monostate_t
 Alias for void_to_monostate<T>::type.
template<class F>
using task
 task_ with noexcept deduced from the function type F (e.g. void() vs void() noexcept).
template<bool... v>
using all_true
template<typename T>
using smart_is_copy_constructible
template<typename T>
using enable_if_copyable
template<typename T>
using enable_if_not_copyable
template<typename... Ts>
using void_t
template<template< class... > class Op, class... Args>
using is_detected
template<template< class... > class Op, class... Args>
using detected_t
template<typename... Ts>
using tuple_cat_t
template<typename... Ts>
using voidless_tuple
template<typename... Ts>
using placeholder_tuple
template<typename... Ts>
using optional_placeholder_tuple
template<class T>
using unwrap_reference_t
using pre_exit_handler
 Function type invoked during pre_exit() (must not throw; noexcept with C++17 and later).
template<class Seq1, class Seq2>
using index_sequence_cat_t
template<class Seq, template< std::size_t > class F, std::size_t Index = 0, std::size_t Count = Seq::size()>
using index_sequence_transform_t

Enumerations

enum class  process_state : std::uint8_t { await , yield }
 Scheduling hint for a process: wait for input (await) or run to produce output (yield).
enum class  message_t : std::uint8_t { argument , error }
 Discriminator for tuple elements that carry either a value or an exception pointer.
enum class  channel_error_codes : std::uint8_t { broken_channel , process_already_running , no_state }
 Error codes reported by channel_error.
enum class  future_error_codes : std::uint8_t { future_error_codes::broken_promise , future_error_codes::no_state }
 Error codes for future_error. More...
enum class  schedule_mode : std::uint8_t { schedule_mode::single , schedule_mode::all }
 How the serial queue drains its task deque when kicked. More...
enum class  forest_edge : bool { trailing , leading }
 Leading and trailing visits in a fullorder walk of a node (see forest iterators).

Functions

template<class BidirectionalRange>
void reverse (BidirectionalRange &range)
 Range-based reverse, will be deprecated in C++20 in favor of std::ranges::reverse.
template<class BidirectionalRange, class OutputIterator>
void reverse_copy (BidirectionalRange &range, OutputIterator result)
 Range-based reverse_copy algorithm, will be deprecated in C++20 in favor of std::ranges::reverse_copy.
template<class BidirectionalRange, class OutputIterator>
void reverse_copy (const BidirectionalRange &range, OutputIterator result)
 Range-based reverse_copy algorithm, will be deprecated in C++20 in favor of std::ranges::reverse_copy.
template<typename I>
auto reverse_until (I f, I m, I l) -> std::pair< I, I >
 Reverses the range [f, l) until m is reached. Returns a range [a, b) of the un-reversed subrange such that either a == m or b == m.
template<class F>
auto invoke_waiting (F &&f)
 Assumes f will block waiting; on the portable task system, wakes the pool or adds a worker (up to the limit) before calling f.
template<class T>
auto await (future< T > &&x) -> T
 Synchronously wait for the result x. If x resolves as an exception, the exception is rethrown. When using the portable task system, an additional thread is added to the pool if no threads are available and the maximum number of threads has not been reached.
template<class T>
auto await (const future< T > &x) -> T
 Equivalent to await(copy(x)).
template<class T>
auto await_for (future< T > &&x, const std::chrono::nanoseconds &timeout) -> future< T >
template<class T>
auto await_for (const future< T > &x, const std::chrono::nanoseconds &timeout) -> future< T >
 Equivalent to await_for(copy(x), timeout).
template<class T>
auto blocking_get (future< T > x) -> T
template<class T>
auto blocking_get_for (future< T > x, const std::chrono::nanoseconds &timeout) -> future< T >
template<class T>
auto blocking_get (future< T > x, const std::chrono::nanoseconds &timeout) -> decltype(x.get_try())
template<typename I, typename N, typename F>
auto for_each_n (I p, N n, F f) -> I
template<typename T, typename E>
auto channel (E executor)
 Creates a sender/receiver pair on executor (receiver<void> only when T is void).
template<typename S, typename F, typename... R>
auto join (S s, F f, R... upstream_receiver)
template<typename S, typename F, typename... R>
auto merge (S s, F f, R... upstream_receiver)
template<typename M, typename S, typename F, typename... R>
auto merge_channel (S s, F f, R &&... upstream_receiver)
 Creates a receiver that merges upstream channels using merge strategy M.
template<typename S, typename F, typename... R>
auto zip_with (S s, F f, const R &... upstream_receiver)
 Creates a receiver that runs f when each upstream has produced one value.
template<typename S, typename... R>
auto zip (S s, const R &... r)
 Zips upstream receivers in step; yields std::tuple<T...> of their result_types.
auto operator& (buffer_size bs, const executor &e) -> detail::annotations
auto operator& (buffer_size bs, executor &&e) -> detail::annotations
auto operator& (const executor &e, buffer_size bs) -> detail::annotations
auto operator& (executor &&e, buffer_size bs) -> detail::annotations
template<typename F, std::enable_if_t<!std::is_enum_v< std::remove_reference_t< F > >, int > = 0>
auto operator& (buffer_size bs, F &&f) -> detail::annotated_process< F >
template<typename F, std::enable_if_t<!std::is_enum_v< std::remove_reference_t< F > >, int > = 0>
auto operator& (F &&f, buffer_size bs) -> detail::annotated_process< F >
template<typename F>
auto operator& (executor_task_pair< F > &&etp, buffer_size bs) -> detail::annotated_process< F >
template<typename F>
auto operator& (buffer_size bs, executor_task_pair< F > &&etp) -> detail::annotated_process< F >
template<typename F, std::enable_if_t<!std::is_enum_v< std::remove_reference_t< F > >, int > = 0>
auto operator& (detail::annotations &&a, F &&f) -> detail::annotated_process< F >
template<typename F, std::enable_if_t<!std::is_enum_v< std::remove_reference_t< F > >, int > = 0>
auto operator& (F &&f, detail::annotations &&a) -> detail::annotated_process< F >
template<typename F>
auto operator& (detail::annotated_process< F > &&a, executor &&e) -> detail::annotated_process< F >
template<typename F>
auto operator& (detail::annotated_process< F > &&a, buffer_size bs) -> detail::annotated_process< F >
template<typename Rep, typename Per = std::ratio<1>>
auto execute_at (std::chrono::duration< Rep, Per > duration, executor_t executor) -> executor_t
 Returns an executor that posts tasks to executor after duration (immediate if zero).
auto execute_at (std::chrono::steady_clock::time_point when, executor_t executor) -> executor_t
template<typename E, typename Rep, typename Per = std::ratio<1>>
auto execute_delayed (std::chrono::duration< Rep, Per > duration, E executor)
 Returns an executor that delays each submitted task by duration before forwarding to executor.
template<typename F>
auto operator& (executor e, F &&f) -> executor_task_pair< F >
template<typename F>
auto operator& (F &&f, executor e) -> executor_task_pair< F >
template<class F, class... Args>
auto invoke_void_to_monostate_result (F &&f, Args &&... args)
 Invokes f with args and returns its result, or std::monostate{} if the result is void.
template<class T>
auto optional_monostate_to_bool (std::optional< T > &&o)
 Returns o.has_value() when T is std::monostate, otherwise std::move(o).
template<class T>
auto monostate_to_void (T &&a)
 Converts std::monostate to void (no return); forwards other types unchanged.
template<class T>
auto monostate_to_empty_tuple (T &&a)
 Converts std::monostate to std::tuple{}; wraps other types in std::tuple for uniform application.
template<class F, class... Args>
auto invoke_remove_monostate_arguments (F &&f, Args &&... args)
 Invokes f with args after removing std::monostate values (for void future results).
template<class Sig, class E, class F>
auto package (E executor, F &&f) -> std::pair< detail::packaged_task_from_signature_t< Sig >, detail::reduced_result_t< Sig > >
 Creates a packaged task and its future for the callable f, run on executor.
template<class T, class E>
auto future_with_broken_promise (E executor) -> detail::reduced_t< T >
 Returns a future of type T that is already ready with a broken_promise error (e.g. for canceled work).
template<class E, class F, class... Ts>
auto when_all (const E &executor, F f, future< Ts >... args)
 Returns a future that completes when all input futures are ready; f receives their values.
template<class E, class F, class T, class... Ts>
auto when_any (E &&executor, F &&f, future< T > &&arg, future< Ts > &&... args)
 Returns a future that completes when any of the given futures is ready; f receives the value and the index of the future that completed first (as a second argument of type std::size_t).
template<class E, class F, class I>
auto when_all (const E &executor, F f, std::pair< I, I > range)
 Returns a future that completes when all futures in [range.first, range.second) are ready; f receives their values.
template<class E, class F, class I>
auto when_any (const E &executor, F &&f, std::pair< I, I > range)
 Returns a future that completes when any future in [range.first, range.second) is ready; f receives the result and the index of the future that completed first (as a second argument of type std::size_t).
template<class E, class F, class... Args>
auto async (const E &executor, F &&f, Args &&... args) -> detail::reduced_t< detail::result_t< std::decay_t< F >, std::decay_t< Args >... > >
 Runs f with args on executor and returns a future for the result.
template<typename T, typename E>
auto make_ready_future (T &&x, E executor) -> future< std::decay_t< T > >
 Creates a future already completed with x (executor runs attached continuations).
template<typename E>
auto make_ready_future (E executor) -> future< void >
 Creates a future<void> already completed (executor runs attached continuations).
template<typename T, typename E>
auto make_exceptional_future (const std::exception_ptr &error, E executor) -> future< T >
 Creates a future already failed with error (executor runs attached continuations).
void set_current_thread_name (const char *name)
template<typename T, typename Op>
auto tuple_find (const T &t, Op op) -> std::size_t
template<typename T, typename Op>
void tuple_for_each (T &t, Op op)
template<typename T, typename F, typename D>
auto get_i (T &t, std::size_t index, F f, D &&default_v)
template<typename T, typename F>
auto void_i (T &t, std::size_t index, F &&f)
template<class F, class Tuple>
constexpr auto apply_ignore_placeholders (F &&f, Tuple &&t) -> decltype(auto)
template<class Seq, class F, class Tuple>
constexpr auto apply_indexed (F &&f, Tuple &&t) -> decltype(auto)
constexpr auto pivot (forest_edge e)
 Toggles a forest_edge between leading and trailing.
template<class I>
void pivot (I &i)
 Flips the edge on iterator i in place.
template<class I>
auto pivot_of (I i)
 Returns a copy of i with its edge toggled (pivot).
template<class I>
auto leading_of (I i)
 Positions i on the leading edge of the same node.
template<class I>
auto trailing_of (I i)
 Positions i on the trailing edge of the same node.
constexpr auto is_leading (forest_edge e)
 True if e is a leading-edge position.
template<class I>
auto is_leading (const I &i)
 True if iterator i is on its node’s leading edge.
constexpr auto is_trailing (forest_edge e)
 True if e is a trailing-edge position.
template<class I>
auto is_trailing (const I &i)
 True if iterator i is on its node’s trailing edge.
template<class I>
auto find_parent (I i) -> I
 Returns the trailing-edge iterator of the parent of the subtree containing i.
template<class I>
auto has_children (const I &i) -> bool
template<class I>
auto find_edge (I x, forest_edge edge) -> I
 Advances x forward until x.edge() == edge (or returns last such position).
template<class I>
auto find_edge_reverse (I x, forest_edge edge) -> I
 Advances x backward until x.edge() == edge.
template<class T>
auto operator== (const forest< T > &x, const forest< T > &y) -> bool
template<class T>
auto operator!= (const forest< T > &x, const forest< T > &y) -> bool
template<class I>
auto child_begin (const I &x) -> child_iterator< I >
 First child iterator for the node referenced by fullorder iterator x (may equal child_end).
template<class I>
auto child_end (const I &x) -> child_iterator< I >
 One-past-last child iterator for the node referenced by x (half-open child sequence).
template<class I>
auto child_range (const I &x)
 forest_range of child_iterator over the immediate children of the node at x.
template<class R, typename P>
auto filter_fullorder_range (R &x, P p)
 Range of filter_fullorder_iterator over x using predicate p.
template<class R, typename P>
auto filter_fullorder_range (const R &x, P p)
 const overload: filters over const_iterators.
template<class R>
auto reverse_fullorder_range (R &x)
 Reverses the fullorder traversal of x (see reverse_fullorder_iterator).
template<class R>
auto reverse_fullorder_range (const R &x)
 const overload.
template<class R>
auto depth_range (R &x)
 Fullorder walk with depth tracking over x (depth_fullorder_iterator).
template<class R>
auto depth_range (const R &x)
 const overload.
template<class R>
auto postorder_range (R &x)
 Postorder (trailing-edge) walk over x.
template<class R>
auto postorder_range (const R &x)
 const overload.
template<class R>
auto preorder_range (R &x)
template<class R>
auto preorder_range (const R &x)
 const overload.
template<typename T>
auto unwrap (T &val) -> T &
 Unwraps val, forwarding through std::reference_wrapper when present.
template<typename T>
auto unwrap (const T &val) -> const T &
template<typename T>
auto unwrap (std::reference_wrapper< T > &val) -> T &
template<typename T>
auto unwrap (const std::reference_wrapper< T > &val) -> const T &
template<typename T>
auto make_weak_ptr (const std::shared_ptr< T > &x)
 Returns a std::weak_ptr<T> sharing ownership with x.
void stlab_pre_exit ()
 An extern "C" vector for pre-exit() to make it simpler to export the function from a shared library.
void stlab_at_pre_exit (pre_exit_handler f)
 An extern "C" vector for at_pre-exit() to make it simpler to export the function from a shared library.
void pre_exit ()
 Invoke all registered pre-exit handlers in the reverse order they are registered. It is safe to register additional handlers during this operation. Must be invoked exactly once prior to program exit.
void at_pre_exit (pre_exit_handler f)
 Register a pre-exit handler. The pre-exit-handler may not throw. With C++17 or later it is required to be noexcept.
template<typename T, typename... Args>
auto scope (Args &&... args)
 Scopes the lifetime of an instance of T. All but the last arguments construct T; the last argument is a nullary function invoked while T is alive. T is destroyed after that function returns.
template<typename T, typename F>
auto scope (std::mutex &m, F &&f)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<bool P, class T>
constexpr auto move_if (T &&t) noexcept -> detail::move_if_helper_t< P, T >
 If P is true, casts t to an rvalue; otherwise keeps an lvalue reference.
template<class F, class... Args>
void for_each_argument (F &&f, Args &&... args)
 Invokes f(arg0), f(arg1), … f(argN).
template<typename T>
constexpr auto copy (T &&value) noexcept(noexcept(std::decay_t< T >{static_cast< T && >(value)})) -> std::decay_t< T >
 Returns a copy of the argument. Used to pass an lvalue to a function taking an rvalue, or to copy a type with an explicit copy constructor.
template<class T>
constexpr auto move (T &&t) noexcept -> std::remove_reference_t< T > &&
 A standard move implementation but with a compile-time check for const types.

Variables

constexpr process_state_scheduled await_forever
 Always await the next upstream value (no yield timeout).
constexpr process_state_scheduled yield_immediate
 Yield as soon as the scheduler permits.
constexpr auto low_executor
 Default task pool executor using low thread priority (when using the portable or Windows task system).
constexpr auto default_executor
 Default concurrent executor used by stlab::async and related APIs when none is specified.
constexpr auto high_executor
 Default task pool executor using high thread priority (when using the portable or Windows task system).
template<class T>
constexpr bool is_monostate_v
 True if T is std::monostate.
constexpr auto immediate_executor
 Invokes work inline on the calling thread (synchronous executor).
constexpr auto main_executor
 Runs void() noexcept tasks on the process main thread (Qt, libdispatch, or Emscripten as configured).
constexpr auto system_timer
 Schedules void() noexcept tasks on a system timer / run loop (platform-dependent).
template<typename T>
constexpr bool smart_is_copy_constructible_v
template<template< class... > class Op, class... Args>
constexpr bool is_detected_v
constexpr auto forest_trailing_edge
constexpr auto forest_leading_edge
template<class T>
constexpr bool is_reference_wrapper_v