複数のファイルを1つの Range として扱いたい 続き

昨日の続き。
コメントで oven::memoized を使用すればうまくいくと教えてもらいました。
と、いう事でこんな感じになりました。

[ソース]

#define BOOST_RESULT_OF_USE_DECLTYPE

#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <boost/range/adaptor/transformed.hpp>
#include <pstade/oven/concatenated.hpp>
#include <pstade/oven/copied.hpp>
#include <pstade/oven/file_range.hpp>
#include <pstade/oven/memoized.hpp>
#include <pstade/oven/distance.hpp>
#include <pstade/oven/filtered.hpp>


int
main(){
    namespace a = boost::adaptors;
    namespace o = pstade::oven;

    std::vector<std::string> filenames;
    filenames.push_back("file.txt");
    filenames.push_back("file2.txt");

    auto result = o::distance(
        filenames
            |a::transformed([](std::string const& filename){
                return pstade::oven::file_range<char>(filename);
            })
            |o::memoized
            |o::concatenated
            |o::filtered([](char c){ return c == ' '; })
    );
    std::cout << result << std::endl;

    return 0;
}


うむうむ、だいぶすっきりしましたね。
Boost.Filesystem とか使えばディレクトリ内のファイル検索とかワンライナーでできそう。