oven::cycled

cycledは、元となる範囲から循環する範囲(circular range)を作成するRangeアダプタです。

以下の場合は、"abc"を3回繰り返す範囲を生成しています。

#include <iostream>
#include <string>
#include <pstade/oven/algorithm.hpp>
#include <pstade/oven/cycled.hpp>

using namespace pstade::oven;

struct disp {
    template <class T>
    void operator()(T x) const
    { std::cout << x; }
};

int main()
{
    for_each(std::string("abc")|cycled(3), disp());
}
abcabcabc


引数を渡さない場合は、無限に繰り返す範囲が作成されます。
以下の場合は、"abc"を無限に繰り返す範囲からtakenで先頭15個を取り出しています。

#include <iostream>
#include <string>
#include <pstade/oven/algorithm.hpp>
#include <pstade/oven/cycled.hpp>
#include <pstade/oven/taken.hpp>

using namespace pstade::oven;

struct disp {
    template <class T>
    void operator()(T x) const
    { std::cout << x; }
};

int main()
{
    for_each(std::string("abc")|cycled|taken(15), disp());
}
abcabcabcabcabc


【参照】
pstade::oven::cycled