■
もう一回ワンライナー。
今回はこちらのネタをお借りしまして
http://d.hatena.ne.jp/nagoya313/20100619/1276954186
#include <fstream> #include <string> #include <list> #include <boost/regex.hpp> #include <boost/shared_ptr.hpp> #include <boost/make_shared.hpp> #include <pstade/oven/stream_lines.hpp> #include <pstade/oven/foreach.hpp> #include <pstade/oven/copied.hpp> #include <pstade/oven/matches.hpp> #include <pstade/oven/reversed.hpp> #include <pstade/oven/stream_writer.hpp> #include <pstade/oven/algorithm.hpp> #include <pstade/oven/any_range.hpp> #define BOOST_LIB_NAME boost_regex #include <boost/config/auto_link.hpp> #define PO pstade::oven /* int main() { if(std::ifstream fin = std::ifstream("constitute.txt")) { if(std::ofstream fout = std::ofstream("reverse.txt")) { if(boost::shared_ptr<std::list<boost::smatch>> v = boost::make_shared<std::list<boost::smatch>>()){ PSTADE_OVEN_FOREACH(str, PO::stream_lines(fin)) { if( &PO::copy( PO::any_range<boost::smatch, boost::bidirectional_traversal_tag>(*v = str|PO::matches(boost::regex("\\s+|\\w+|\\W"))|PO::copied)|PO::reversed, PO::stream_writer(fout) ) ) {} if(fout << std::endl) {} } } } } } */ int main(){if(std::ifstream fin=std::ifstream("constitute.txt")){if(std::ofstream fout=std::ofstream("reverse.txt")){if(boost::shared_ptr<std::list<boost::smatch>> v=boost::make_shared<std::list<boost::smatch>>()){PSTADE_OVEN_FOREACH(str,PO::stream_lines(fin)){if(&PO::copy(PO::any_range<boost::smatch,boost::bidirectional_traversal_tag>(*v=str|PO::matches(boost::regex("\\s+|\\w+|\\W"))|PO::copied)|PO::reversed,PO::stream_writer(fout))){}if(fout<<std::endl){}}}}}}
pstade.oven最強過ぎる・・・