Skip to content
Vlad Riscutia edited this page Nov 7, 2016 · 2 revisions

Header pipe/generator.h, in namespace pipe::generator.

template <template <typename, typename> typename Generator = std::experimental::generator,
          typename Allocator = std::allocator<char>, typename Func>
auto repeat(Func func) -> Generator<typename std::result_of<Func()>::type, Allocator>;

repeat infinitely calls the given function func and yields its return value.

Example:

std::vector<int> out { };
repeat(constant(42)) | take_n(5) | collect(std::back_inserter(out)); 
// out contains { 42, 42, 42, 42, 42 }
Clone this wiki locally