C++類庫:P-Stade.Oven

來源:互聯網
上載者:User
文章目錄
  • 關於P-Stade.Oven
  • 範例程式碼
 關於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,
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.