Boost C++ Libraryのお勉強その12
http://www.boost.org/doc/libs/1_35_0
webブラウザのスクロールバーの位置からすると、やっと半分てところか。
Boost.Iostream
IO streamが簡単に作れる仕組み。
#include <iostream> #include <boost/iostreams/stream.hpp> #include <boost/iostreams/concepts.hpp> class zero : public boost::iostreams::source { public: std::streamsize read(char * s, std::streamsize n) { *s = '0'; return 1; } }; int main(void) { char c; zero z; boost::iostreams::stream <zero> s(z); s >> c; std::cout << c << std::endl; return 0; }
Boost.Iterator
イテレータ色々。
#include <iostream> #include <numeric> #include <boost/iterator/counting_iterator.hpp> int main(void) { boost::counting_iterator<int> s(1); boost::counting_iterator<int> e(10); std::cout << std::accumulate(s, e, 0) << std::endl; }
45
Boost.Lambda
無名関数環境付きとかそんな感じのもの。感動の一品ではあるが、流石にメンバ関数呼び出しとかはキツい…。
#include <iostream> #include <vector> #include <algorithm> #include <boost/lambda/lambda.hpp> int main(void) { using namespace boost::lambda; std::vector < int > v; v.push_back(1); v.push_back(2); v.push_back(3); int sum = 0; std::for_each(v.begin(), v.end(), sum += _1); std::cout << sum << std::endl; return 0; }
6