文章目錄
關於P-Stade.Oven P-Stade.Oven是一個Boost.Range的擴充庫,同時也是Range Library Proposal提案的一個具體實現。藉助於這個類庫,我們就能在Range上實施STL演算法,從而獲得更為簡潔清晰的代碼。 範例程式碼#include<iostream><br />#include<vector><br />#include <pstade/oven.hpp><br />#include <boost/lambda/lambda.hpp><br />#include <boost/spirit/include/karma.hpp><br />#include <boost/spirit/include/phoenix.hpp><br />#include <boost/assign.hpp><br />#include <boost/foreach.hpp></p><p>using namespace std;<br />using namespace pstade::oven;<br />using namespace boost::assign;<br />namespace karma = boost::spirit::karma;<br />namespace lambda = boost::lambda;<br />namespace phoenix = boost::phoenix;</p><p>double g(int i){return i + 1.5;}</p><p>int main()<br />{<br />vector<int> v;<br />v += 1,2,3;</p><p>auto v2 = v | transformed(lambda::_1 + 1.5);<br />cout << karma::format(karma::auto_ % ',', v2) << endl; // error with gcc4.5</p><p>auto v3 = v | transformed(phoenix::arg_names::_1 + 1.5);<br />BOOST_FOREACH(double i, v3) // error with gcc4.5<br />cout << i << ',';<br />cout << endl;</p><p>//auto v4 = v | transformed([](int elem){return elem + 1.5;}); // error<br />function<double(int)> f = [](int elem){return elem + 1.5;};<br />auto v4 = v | transformed(f);<br />PSTADE_OVEN_FOREACH(i, v4) // error with gcc4.5<br />cout << i << ',';<br />cout << endl;</p><p>auto v5 = v | transformed(g);<br />for(auto i = v5.begin(); i != v5.end(); ++i) // error with gcc4.5<br />cout << *i << ',';<br />cout << endl;</p><p>return 0;<br />}</p><p>//2.5,3.5,4.5<br />//2.5,3.5,4.5,<br />//2.5,3.5,4.5,<br />//2.5,3.5,4.5,