Connections module
provides functions to connect continuable_
Contents
- Reference
Functions
-
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.
Function documentation
template<typename... Args>
auto when_all(Args && ... args)
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.
Parameters | |
---|---|
args | Arbitrary arguments which are connected. Every type is allowed as arguments, continuables may be contained inside tuple like types ( cti::when_all( cti::make_ready_continuable(0, 1), 2, //< See this plain value cti::populate(cti::make_ready_continuable(3), // Creates a runtime cti::make_ready_continuable(4)), // sized container. std::make_tuple(std::make_tuple(cti::make_ready_continuable(5)))) .then([](int r0, int r1, int r2, std::vector<int> r34, std::tuple<std::tuple<int>> r5) { // ... }); |
template<typename Iterator, std::enable_if_t<detail::range::is_iterator<Iterator>::value>* = nullptr>
auto when_all(Iterator begin,
Iterator end)
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.
Parameters | |
---|---|
begin | The begin iterator to the range which will be moved out and used as the arguments to the all connection |
end | The end iterator to the range which will be moved out and used as the arguments to the all connection |
// cti::populate just creates a std::vector from the two continuables. auto v = cti::populate(cti::make_ready_continuable(0), cti::make_ready_continuable(1)); cti::when_all(v.begin(), v.end()) .then([](std::vector<int> r01) { // ... });
template<typename... Args>
auto when_seq(Args && ... args)
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.
Parameters | |
---|---|
args | Arbitrary arguments which are connected. Every type is allowed as arguments, continuables may be contained inside tuple like types ( cti::when_seq( cti::make_ready_continuable(0, 1), 2, //< See this plain value cti::populate(cti::make_ready_continuable(3), // Creates a runtime cti::make_ready_continuable(4)), // sized container. std::make_tuple(std::make_tuple(cti::make_ready_continuable(5)))) .then([](int r0, int r1, int r2, std::vector<int> r34, std::tuple<std::tuple<int>> r5) { // ... }); |
template<typename Iterator, std::enable_if_t<detail::range::is_iterator<Iterator>::value>* = nullptr>
auto when_seq(Iterator begin,
Iterator end)
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.
Parameters | |
---|---|
begin | The begin iterator to the range which will be moved out and used as the arguments to the sequential connection |
end | The end iterator to the range which will be moved out and used as the arguments to the sequential connection |
// cti::populate just creates a std::vector from the two continuables. auto v = cti::populate(cti::make_ready_continuable(0), cti::make_ready_continuable(1)); cti::when_seq(v.begin(), v.end()) .then([](std::vector<int> r01) { // ... });
template<typename... Args>
auto when_any(Args && ... args)
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.
Parameters | |
---|---|
args | Arbitrary arguments which are connected. Every type is allowed as arguments, continuables may be contained inside tuple like types ( cti::when_any( cti::make_ready_continuable(0, 1), 2, //< See this plain value cti::populate(cti::make_ready_continuable(3), // Creates a runtime cti::make_ready_continuable(4)), // sized container. std::make_tuple(std::make_tuple(cti::make_ready_continuable(5)))) .then([](int r0) { // ... }); |
template<typename Iterator, std::enable_if_t<detail::range::is_iterator<Iterator>::value>* = nullptr>
auto when_any(Iterator begin,
Iterator end)
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.
Parameters | |
---|---|
begin | The begin iterator to the range which will be moved out and used as the arguments to the all connection |
end | The end iterator to the range which will be moved out and used as the arguments to the all connection |
// cti::populate just creates a std::vector from the two continuables. auto v = cti::populate(cti::make_ready_continuable(0), cti::make_ready_continuable(1)); cti::when_any(v.begin(), v.end()) .then([](int r01) { // ... });
template<template<typename, typename> class C = std::vector, typename First, typename... Args>
C<std::decay_t<First>, std::allocator<std::decay_t<First>>> populate(First&& first,
Args && ... args)
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 parameters | |
---|---|
C | The container type which is used to store the arguments into. |
First | |
Args |
This method mainly helps to create a homogeneous container from a runtime known count of continuables which type isn't exactly known. All continuables which are passed to this function should be originating from the same source or a method called with the same types of arguments:
auto container = cti::populate(cti::make_ready_continuable(0), cti::make_ready_continuable(1)), for (int i = 2; i < 5; ++i) { // You may add more continuables to the container afterwards container.emplace_back(cti::make_ready_continuable(i)); } cti::when_any(std::move(container)) .then([](int) { // ... });
Additionally it is possible to change the targeted container as below:
auto container = cti::populate<std::list>(cti::make_ready_continuable(0), cti::make_ready_continuable(1)),