pstade/oven/io.hpp
[お題]
std::vector や int[] を標準出力したい。
#include <iostream> #include <list> #include <pstade/oven/io.hpp> #include <pstade/oven/identities.hpp> #include <pstade/oven/filtered.hpp> #include <pstade/oven/copied.hpp> #include <boost/lambda/lambda.hpp> int main(){ namespace oven = pstade::oven; namespace lambda = boost::lambda; int array[] = {0, 1, 2, 3, 4}; // range を標準出力してくれるよ std::cout << oven::make_iter_range(array) << std::endl; // こういう書き方でも OK std::cout << (array|oven::identities) << std::endl; // range が返れば何でもいいです std::cout << (array|oven::filtered(lambda::_1 % 2 == 0)) << std::endl; // 他のコンテナ型でも問題にゃーい std::list<int> array2 = array|oven::copied; std::cout << (array2|oven::identities) << std::endl; return 0; }
[出力]
{0,1,2,3,4} {0,1,2,3,4} {0,2,4} {0,1,2,3,4}
pstade/oven/io.hpp を include すれば、stream に対して、range の出力を行ってくれます。
[pstade]
ver 1.04.3