From de40af0927b12f052f7a8a5f6244748306d24ca1 Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Fri, 9 Mar 2018 09:43:58 +0100 Subject: [PATCH] Add cti::populate and make use of it in tests --- .../continuable/continuable-compositions.hpp | 46 +++++++++++++++++++ include/continuable/detail/range.hpp | 11 +++-- test/playground/test-playground.cpp | 30 ++++++------ .../test-continuable-connection-all-seq.hpp | 11 +---- .../multi/test-continuable-connection-any.cpp | 11 +---- 5 files changed, 72 insertions(+), 37 deletions(-) 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