pstade::oven::rows(height, width)

#include <iostream>

#include <boost/range/algorithm/for_each.hpp>

#include <pstade/oven/matrix.hpp>
#include <pstade/oven/at.hpp>

int
main(){
    namespace oven = pstade::oven;
    using oven::at;

    int array[] = {0, 1, 2, 3, 4, 5, 6, 7};
    int array2[2][4] = {
        {0, 1, 2, 3},
        {4, 5, 6, 7},
    };

    assert( (array|oven::rows(2, 4)|at(1)|at(2)) == array2[1][2] );

    boost::for_each(array|oven::rows(2, 4), [](oven::iter_range<int*> range){
        boost::for_each(range, [](int n){
            std::cout << n;
        });
        std::cout << std::endl;
    });

    return 0;
}


[出力]

0123
4567


pstade::oven::rows(height, width) は、range を2次元配列のような形にして返します。

int array[] = {
    0, 1, 2,
    3, 4, 5
};
array|oven::rows(2, 3); // { {0, 1, 2}, {3, 4, 5} }


height と width の渡す順番が逆のような気もしますが、よくよく長えると2次元配列も同じような順番ですね。
今のところ特に目立った使い方は思いつきませんが、さて。


[pstade]
ver 1.04.3