diff --git a/include/continuable/continuable-compositions.hpp b/include/continuable/continuable-compositions.hpp index 0fc2a70..0886481 100644 --- a/include/continuable/continuable-compositions.hpp +++ b/include/continuable/continuable-compositions.hpp @@ -31,7 +31,10 @@ #ifndef CONTINUABLE_COMPOSITIONS_HPP_INCLUDED #define CONTINUABLE_COMPOSITIONS_HPP_INCLUDED +#include +#include #include +#include #include #include @@ -242,6 +245,49 @@ template < auto when_any(Iterator begin, Iterator end) { return when_any(detail::range::persist_range(begin, end)); } + +/// 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. +/// +/// 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: +/// ```cpp +/// 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: +/// ```cpp +/// auto container = cti::populate(cti::make_ready_continuable(0), +/// cti::make_ready_continuable(1)), +/// ``` +/// +/// \tparam C The container type which is used to store the arguments into. +/// +/// \since 3.0.0 +template