Skip to content

Commit a7ffe9a

Browse files
authored
pipeline: add tuple constructor (taskflow#377)
1 parent 2294587 commit a7ffe9a

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

taskflow/algorithm/pipeline.hpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,14 @@ class Pipeline {
269269
PipeType type;
270270
};
271271

272+
/**
273+
@private
274+
*/
275+
template <std::size_t... indices>
276+
inline static std::array<PipeMeta, sizeof...(Ps)> gen_meta(std::tuple<Ps...>&& ps, std::index_sequence<indices...>) {
277+
return {PipeMeta{std::get<indices>(ps)._type}...};
278+
}
279+
272280
public:
273281

274282
/**
@@ -284,6 +292,19 @@ class Pipeline {
284292
*/
285293
Pipeline(size_t num_lines, Ps&&... ps);
286294

295+
/**
296+
@brief constructs a pipeline object
297+
298+
@param num_lines the number of parallel lines
299+
@param ps a tuple of pipes
300+
301+
Constructs a linear pipeline of up to @c num_lines concurrent
302+
scheduling tokens flowing through the given linear chain of pipes.
303+
The first pipe must define a serial direction (tf::PipeType::SERIAL)
304+
or an exception will be thrown.
305+
*/
306+
Pipeline(size_t num_lines, std::tuple<Ps...>&& ps);
307+
287308
/**
288309
@brief queries the number of parallel lines
289310
@@ -360,6 +381,23 @@ Pipeline<Ps...>::Pipeline(size_t num_lines, Ps&&... ps) :
360381
_build();
361382
}
362383

384+
// constructor
385+
template <typename... Ps>
386+
Pipeline<Ps...>::Pipeline(size_t num_lines, std::tuple<Ps...>&& ps) :
387+
_pipes {std::forward<std::tuple<Ps...>>(ps)},
388+
_meta {gen_meta(std::forward<std::tuple<Ps...>>(ps), std::make_index_sequence<sizeof...(Ps)>{})},
389+
_lines (num_lines),
390+
_tasks (num_lines + 1),
391+
_pipeflows (num_lines) {
392+
393+
if(std::get<0>(_pipes)._type == PipeType::PARALLEL) {
394+
TF_THROW("first pipe must be serial");
395+
}
396+
397+
reset();
398+
_build();
399+
}
400+
363401
// Function: num_lines
364402
template <typename... Ps>
365403
size_t Pipeline<Ps...>::num_lines() const noexcept {

0 commit comments

Comments
 (0)