锘??xml version="1.0" encoding="utf-8" standalone="yes"?>国产精品久久国产精品99盘,一本大道加勒比久久综合,久久免费国产精品一区二区http://www.shnenglu.com/yindf/category/9614.html鍔姏鐮旂┒C++zh-cnTue, 24 Feb 2009 08:51:39 GMTTue, 24 Feb 2009 08:51:39 GMT60娣卞叆鎺㈢儲 boost::lambda 緋誨垪錛堜笁錛?/title><link>http://www.shnenglu.com/yindf/articles/74616.html</link><dc:creator>灝逛笢鏂?/dc:creator><author>灝逛笢鏂?/author><pubDate>Sun, 22 Feb 2009 14:11:00 GMT</pubDate><guid>http://www.shnenglu.com/yindf/articles/74616.html</guid><wfw:comment>http://www.shnenglu.com/yindf/comments/74616.html</wfw:comment><comments>http://www.shnenglu.com/yindf/articles/74616.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/yindf/comments/commentRss/74616.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/yindf/services/trackbacks/74616.html</trackback:ping><description><![CDATA[<br>鐪嬬湅涔嬪墠鍋氬埌鍝噷浜嗭細瀹炵幇浜嗕竴涓祴鍊肩殑lambda琛ㄨ揪寮忋?br><br>榪欐鏉ョ湅鐪嬫庝箞娣誨姞鏂扮殑榪愮畻榪涘幓錛岀劧鍚庡啀璇寸偣鍏充簬琛ㄨ揪寮忕殑闂錛屼負浠ュ悗鐨勬墿灞曟墦涓嬬悊璁哄熀紜銆?br><br>鍏堢湅鐪嬩箣鍓嶇殑浠g爜鍚э紝<br><br> <div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; width: 98%; font-family: courier new; font-size: 13px;"><span style="color: #008080;"> 1</span> <span style="color: #000000;">template </span><span style="color: #000000;"><</span><span style="color: #000000;">typename _U</span><span style="color: #000000;">></span><span style="color: #000000;"><br></span><span style="color: #008080;"> 2</span> <span style="color: #000000;"></span><span style="color: #0000ff;">struct</span><span style="color: #000000;"> op<br></span><span style="color: #008080;"> 3</span> <span style="color: #000000;">{<br></span><span style="color: #008080;"> 4</span> <span style="color: #000000;">    op(_U i)<br></span><span style="color: #008080;"> 5</span> <span style="color: #000000;">        : _i(i)<br></span><span style="color: #008080;"> 6</span> <span style="color: #000000;">    {}<br></span><span style="color: #008080;"> 7</span> <span style="color: #000000;"><br></span><span style="color: #008080;"> 8</span> <span style="color: #000000;">    _U _i;<br></span><span style="color: #008080;"> 9</span> <span style="color: #000000;"><br></span><span style="color: #008080;">10</span> <span style="color: #000000;">    template</span><span style="color: #000000;"><</span><span style="color: #000000;">typename _T</span><span style="color: #000000;">></span><span style="color: #000000;"><br></span><span style="color: #008080;">11</span> <span style="color: #000000;">    _T</span><span style="color: #000000;">&</span><span style="color: #000000;"> </span><span style="color: #0000ff;">operator</span><span style="color: #000000;">()(_T</span><span style="color: #000000;">&</span><span style="color: #000000;"> i)<br></span><span style="color: #008080;">12</span> <span style="color: #000000;">    {<br></span><span style="color: #008080;">13</span> <span style="color: #000000;">        i </span><span style="color: #000000;">=</span><span style="color: #000000;"> _i;<br></span><span style="color: #008080;">14</span> <span style="color: #000000;">    }<br></span><span style="color: #008080;">15</span> <span style="color: #000000;">};<br></span><span style="color: #008080;">16</span> <span style="color: #000000;"><br></span><span style="color: #008080;">17</span> <span style="color: #000000;"></span><span style="color: #0000ff;">struct</span><span style="color: #000000;"> place_holder<br></span><span style="color: #008080;">18</span> <span style="color: #000000;">{<br></span><span style="color: #008080;">19</span> <span style="color: #000000;">    template </span><span style="color: #000000;"><</span><span style="color: #000000;">typename _T</span><span style="color: #000000;">></span><span style="color: #000000;"><br></span><span style="color: #008080;">20</span> <span style="color: #000000;">    op</span><span style="color: #000000;"><</span><span style="color: #000000;">_T</span><span style="color: #000000;">></span><span style="color: #000000;"> </span><span style="color: #0000ff;">operator</span><span style="color: #000000;">=</span><span style="color: #000000;">(_T i)<br></span><span style="color: #008080;">21</span> <span style="color: #000000;">    {<br></span><span style="color: #008080;">22</span> <span style="color: #000000;">        </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> op</span><span style="color: #000000;"><</span><span style="color: #000000;">_T</span><span style="color: #000000;">></span><span style="color: #000000;">(i)<br></span><span style="color: #008080;">23</span> <span style="color: #000000;">    }<br></span><span style="color: #008080;">24</span> <span style="color: #000000;">};<br></span><span style="color: #008080;">25</span> <span style="color: #000000;"><br></span><span style="color: #008080;">26</span> <span style="color: #000000;">place_holder _1;<br></span><span style="color: #008080;">27</span> <span style="color: #000000;"><br></span><span style="color: #008080;">28</span> <span style="color: #000000;">vector</span><span style="color: #000000;"><</span><span style="color: #0000ff;">double</span><span style="color: #000000;">></span><span style="color: #000000;"> v;<br></span><span style="color: #008080;">29</span> <span style="color: #000000;">for_each(v.begin(), v.end(), _1 </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #000000;">3</span><span style="color: #000000;">);</span></div> <br>鐜板湪錛岃鍦ㄨ繖涓熀紜涓婏紝娣誨姞鏂扮殑鎿嶄綔榪涙潵錛屾瘮濡傝operator+=鍚с傝鎬庝箞鍋氬憿錛?br><br>1.  place_holder瑕侀噸杞給perator+= 鎵嶅彲浠ワ紝鍥犱負place_holder鐨勪富瑕佷換鍔″氨鏄浛鎴戜滑鐢熸垚涓涓豢鍑芥暟銆?br>2.  瑕佹湁鐩稿簲鐨勪豢鍑芥暟鏉ョ湡姝g殑鍋?+= 錛屼篃灝辨槸璇村湪浠垮嚱鏁扮殑operator()閲岄潰錛岃鏈夌湡姝e共媧葷殑鎿嶄綔銆?br><br>濂戒簡錛屽紑濮嬪惂錛?鍏堢湅鐪嬪疄鐜幫紝鐒跺悗鍦ㄨВ閲娿?br><br> <div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; width: 98%; font-family: courier new; font-size: 13px;"><span style="color: #008080;"> 1</span> <span style="color: #0000ff;">struct</span><span style="color: #000000;"> op<br></span><span style="color: #008080;"> 2</span> <span style="color: #000000;">{<br></span><span style="color: #008080;"> 3</span> <span style="color: #000000;">    op(</span><span style="color: #0000ff;">int</span><span style="color: #000000;"> i)<br></span><span style="color: #008080;"> 4</span> <span style="color: #000000;">        : _i(i)<br></span><span style="color: #008080;"> 5</span> <span style="color: #000000;">    {}<br></span><span style="color: #008080;"> 6</span> <span style="color: #000000;"><br></span><span style="color: #008080;"> 7</span> <span style="color: #000000;">    </span><span style="color: #0000ff;">int</span><span style="color: #000000;"> _i;<br></span><span style="color: #008080;"> 8</span> <span style="color: #000000;"><br></span><span style="color: #008080;"> 9</span> <span style="color: #000000;">    </span><span style="color: #0000ff;">int</span><span style="color: #000000;"> </span><span style="color: #0000ff;">operator</span><span style="color: #000000;">()(</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&</span><span style="color: #000000;"> i)<br></span><span style="color: #008080;">10</span> <span style="color: #000000;">    {<br></span><span style="color: #008080;">11</span> <span style="color: #000000;">        </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> i </span><span style="color: #000000;">=</span><span style="color: #000000;"> _i;<br></span><span style="color: #008080;">12</span> <span style="color: #000000;">    }<br></span><span style="color: #008080;">13</span> <span style="color: #000000;">};<br></span><span style="color: #008080;">14</span> <span style="color: #000000;"><br></span><span style="color: #008080;">15</span> <span style="color: #000000;"></span><span style="color: #0000ff;">struct</span><span style="color: #000000;"> op1<br></span><span style="color: #008080;">16</span> <span style="color: #000000;">{<br></span><span style="color: #008080;">17</span> <span style="color: #000000;">    op1(</span><span style="color: #0000ff;">int</span><span style="color: #000000;"> i)<br></span><span style="color: #008080;">18</span> <span style="color: #000000;">        : _i(i)<br></span><span style="color: #008080;">19</span> <span style="color: #000000;">    {}<br></span><span style="color: #008080;">20</span> <span style="color: #000000;"><br></span><span style="color: #008080;">21</span> <span style="color: #000000;">    </span><span style="color: #0000ff;">int</span><span style="color: #000000;"> _i;<br></span><span style="color: #008080;">22</span> <span style="color: #000000;"><br></span><span style="color: #008080;">23</span> <span style="color: #000000;">    </span><span style="color: #0000ff;">int</span><span style="color: #000000;"> </span><span style="color: #0000ff;">operator</span><span style="color: #000000;">()(</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&</span><span style="color: #000000;"> i)<br></span><span style="color: #008080;">24</span> <span style="color: #000000;">    {<br></span><span style="color: #008080;">25</span> <span style="color: #000000;">        </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> i </span><span style="color: #000000;">+=</span><span style="color: #000000;"> _i;<br></span><span style="color: #008080;">26</span> <span style="color: #000000;">    }<br></span><span style="color: #008080;">27</span> <span style="color: #000000;">};<br></span><span style="color: #008080;">28</span> <span style="color: #000000;"><br></span><span style="color: #008080;">29</span> <span style="color: #000000;"></span><span style="color: #0000ff;">struct</span><span style="color: #000000;"> place_holder<br></span><span style="color: #008080;">30</span> <span style="color: #000000;">{<br></span><span style="color: #008080;">31</span> <span style="color: #000000;">    op </span><span style="color: #0000ff;">operator</span><span style="color: #000000;">=</span><span style="color: #000000;">(</span><span style="color: #0000ff;">int</span><span style="color: #000000;"> i)<br></span><span style="color: #008080;">32</span> <span style="color: #000000;">    {<br></span><span style="color: #008080;">33</span> <span style="color: #000000;">        </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> op(i);<br></span><span style="color: #008080;">34</span> <span style="color: #000000;">    }<br></span><span style="color: #008080;">35</span> <span style="color: #000000;"><br></span><span style="color: #008080;">36</span> <span style="color: #000000;">    op1 </span><span style="color: #0000ff;">operator</span><span style="color: #000000;">+=</span><span style="color: #000000;">(</span><span style="color: #0000ff;">int</span><span style="color: #000000;"> i)<br></span><span style="color: #008080;">37</span> <span style="color: #000000;">    {<br></span><span style="color: #008080;">38</span> <span style="color: #000000;">        </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> op1(i);<br></span><span style="color: #008080;">39</span> <span style="color: #000000;">    }<br></span><span style="color: #008080;">40</span> <span style="color: #000000;">};<br></span><span style="color: #008080;">41</span> <span style="color: #000000;"><br></span><span style="color: #008080;">42</span> <span style="color: #000000;">place_holder _1;<br></span><span style="color: #008080;">43</span> <span style="color: #000000;"><br></span><span style="color: #008080;">44</span> <span style="color: #000000;"></span><span style="color: #0000ff;">void</span><span style="color: #000000;"> main()<br></span><span style="color: #008080;">45</span> <span style="color: #000000;">{<br></span><span style="color: #008080;">46</span> <span style="color: #000000;"><br></span><span style="color: #008080;">47</span> <span style="color: #000000;">    vector</span><span style="color: #000000;"><</span><span style="color: #0000ff;">int</span><span style="color: #000000;">></span><span style="color: #000000;"> v;<br></span><span style="color: #008080;">48</span> <span style="color: #000000;">    v.push_back(</span><span style="color: #000000;">12</span><span style="color: #000000;">);<br></span><span style="color: #008080;">49</span> <span style="color: #000000;">    v.push_back(</span><span style="color: #000000;">1342</span><span style="color: #000000;">);<br></span><span style="color: #008080;">50</span> <span style="color: #000000;">    v.push_back(</span><span style="color: #000000;">23</span><span style="color: #000000;">);<br></span><span style="color: #008080;">51</span> <span style="color: #000000;"><br></span><span style="color: #008080;">52</span> <span style="color: #000000;">    for_each(v.begin(), v.end(), _1 </span><span style="color: #000000;">+=</span><span style="color: #000000;"> </span><span style="color: #000000;">3</span><span style="color: #000000;">);<br></span><span style="color: #008080;">53</span> <span style="color: #000000;">}</span></div> <br>濂戒簡錛岀幇鍦?=鎿嶄綔宸茬粡琚敮鎸佷簡銆傚涔堢畝鍗曞憖銆傛潵鐪嬬湅閮藉仛浜嗕簺浠涔堬細<br><br>1.  緇檖lace_holder澧炲姞浜嗕竴涓猳perator+=鍑芥暟錛?operator+= 榪斿洖op1綾誨瀷鐨勪豢鍑芥暟銆?br>2.  澧炲姞浜嗕竴涓猳p1鐨勪豢鍑芥暟錛堢被妯℃澘錛夛紝鐢ㄦ潵鐪熸鐨勬墽琛?+= 鐨勮繍綆椼?br><br>褰撶紪璇戝櫒鐪嬪埌  _1 += 3 鏃訛紝鍘繪壘鍒?place_holder::operator+=, 鐒跺悗鎶婃ā鏉垮弬鏁版帹瀵兼垚 int錛岃繑鍥炰竴涓?op1<int> 瀵硅薄銆?br>鍦╢or_each閲岄潰錛屽氨璋冪敤op1<int>::operator+=浜嗐?br><br>褰撶劧涔熷彲浠ヨ繖涔堢敤錛?br><br> <div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; width: 98%; font-family: courier new; font-size: 13px;"><span style="color: #008080;">1</span> <span style="color: #0000ff;">double</span><span style="color: #000000;"> x </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #000000;">0.0</span><span style="color: #000000;">;<br></span><span style="color: #008080;">2</span> <span style="color: #000000;">(_1 </span><span style="color: #000000;">+=</span><span style="color: #000000;"> </span><span style="color: #000000;">10.4</span><span style="color: #000000;">)(x);</span></div> <br>鍒拌繖閲屽ぇ瀹舵兂蹇呭凡緇忓彲浠ョ収鐚敾铏庯紝瀹炵幇鍏朵粬鎿嶄綔浜嗗惂銆備絾鏄綋瀹炵幇鐨勬搷浣滃璧鋒潵鐨勬椂鍊欙紝鏂扮殑闂灝辨潵浜嗭紝姣斿鎯寵涓?_1 = _2 + 3.0 鐨勬椂鍊欏憿錛熺湅鐪嬩笅闈㈢殑浠g爜錛?br><br> <div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; width: 98%; font-family: courier new; font-size: 13px;"><span style="color: #008080;"> 1</span> <span style="color: #000000;">_1 </span><span style="color: #000000;">=</span><span style="color: #000000;"> _2 </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #000000;">3.0</span><span style="color: #000000;">    </span><span style="color: #008000;">//</span><span style="color: #008000;">lambda琛ㄨ揪寮?/span><span style="color: #008000;"><br></span><span style="color: #008080;"> 2</span> <span style="color: #008000;"></span><span style="color: #000000;"><br></span><span style="color: #008080;"> 3</span> <span style="color: #000000;"></span><span style="color: #0000ff;">void</span><span style="color: #000000;"> fun(</span><span style="color: #0000ff;">double</span><span style="color: #000000;">&</span><span style="color: #000000;"> lhs, </span><span style="color: #0000ff;">const</span><span style="color: #000000;"> </span><span style="color: #0000ff;">double</span><span style="color: #000000;">&</span><span style="color: #000000;"> rhs)  </span><span style="color: #008000;">//</span><span style="color: #008000;">鐩稿悓鍔熻兘鍑芥暟</span><span style="color: #008000;"><br></span><span style="color: #008080;"> 4</span> <span style="color: #008000;"></span><span style="color: #000000;">{<br></span><span style="color: #008080;"> 5</span> <span style="color: #000000;">    lhs </span><span style="color: #000000;">=</span><span style="color: #000000;"> rhs </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #000000;">3.0</span><span style="color: #000000;">;<br></span><span style="color: #008080;"> 6</span> <span style="color: #000000;">}<br></span><span style="color: #008080;"> 7</span> <span style="color: #000000;"><br></span><span style="color: #008080;"> 8</span> <span style="color: #000000;"></span><span style="color: #0000ff;">struct</span><span style="color: #000000;"> op<br></span><span style="color: #008080;"> 9</span> <span style="color: #000000;">{<br></span><span style="color: #008080;">10</span> <span style="color: #000000;">    template </span><span style="color: #000000;"><</span><span style="color: #000000;">typename _T</span><span style="color: #000000;">></span><span style="color: #000000;"><br></span><span style="color: #008080;">11</span> <span style="color: #000000;">    _T </span><span style="color: #0000ff;">operator</span><span style="color: #000000;">(_T</span><span style="color: #000000;">&</span><span style="color: #000000;"> lhs, </span><span style="color: #0000ff;">const</span><span style="color: #000000;"> _T</span><span style="color: #000000;">&</span><span style="color: #000000;"> rhs)<br></span><span style="color: #008080;">12</span> <span style="color: #000000;">    {<br></span><span style="color: #008080;">13</span> <span style="color: #000000;">        lhs </span><span style="color: #000000;">=</span><span style="color: #000000;"> rhs </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #000000;">3.0</span><span style="color: #000000;">;<br></span><span style="color: #008080;">14</span> <span style="color: #000000;">    }<br></span><span style="color: #008080;">15</span> <span style="color: #000000;">};<br></span><span style="color: #008080;">16</span> <span style="color: #000000;"></span></div> <br>鐪嬬湅lambda琛ㄨ揪寮忎負鎴戜滑鐪佷簡澶氬皯浠g爜錛佸綋鐒舵垜涓嶆槸涓轟簡璇磋繖涓屽啓榪欎箞闀挎浠g爜錛屾垜鎯寵錛岄偅涓猳p鏄垜浠殑鏈緇堢洰鏍囷紝鑳藉疄鐜板悧錛熶笉鑳斤紒鍥犱負鍦╫p閲岄潰鐩存帴鍑虹幇浜?.0錛屾寜鐓у墠闈㈢殑鎯緥錛屽簲璇ュ湪op閲岄潰鏈変竴涓垚鍛樺彉閲忔潵淇濆瓨3.0錛屼笉鏄悧錛熸牴鏈棶棰樹笉鍦ㄨ繖閲屻?br><br>浠旂粏鎯蟲兂鎴戜滑鍒板簳鍦ㄥ仛浠涔堬紝<strong>鎴戜滑鍦ㄧ敤template鐨勬妧娉曪紝“緙栬瘧”琛ㄨ揪寮忋?br></strong>place_holder鍏跺疄灝卞儚C++鐨勮〃杈懼紡錛宱p灝卞儚姹囩紪璇█錛岄氳繃template鎶娉曪紝鎶妏lace_holder鐨勮〃杈懼紡“緙栬瘧”鎴愮敤op緇勬垚鐨勬搷浣滐紝op鏄彲浠ョ洿鎺ヨC++榪愯鐨勪豢鍑芥暟銆備篃灝辨槸璇存槸涓涓粠lambda璇硶鍒癈++璇硶鐨勭紪璇戝櫒錛屼絾鏄繖涓紪璇戝櫒闈爐emplate鎶娉曞疄鐜幫紝鐢辯湡姝g殑C++緙栬瘧鍣ㄨ繘琛屾ā鏉挎帹瀵鹼紝鏈鍚?#8220;緙栬瘧”鎴怌++鐨勪豢鍑芥暟銆傛墍浠ヤ竴鍙ヨ瘽灝辨槸錛?br><br><strong>鐢╰emplate鎶娉曞疄鐜扮殑浠巐ambda璇硶鍒癈++璇硶鐨?#8220;緙栬瘧鍣?#8221;銆?br><br></strong>鎵浠ユ牴鏈棶棰樺湪浜巓p鐨勮繖縐嶅啓娉曟病鏈夊姙娉曟墿灞曪紝闅鵑亾瀵逛簬姣忕榪炶搗鏉ョ殑鎿嶄綔錛岄兘鍒嗗埆鍐欎竴涓猳p鍚楋紙姣斿_1 = (_2 + 3.0) * (_2 - 3.0)錛孋++涓〃杈懼紡鏃犳暟錛岃鏄瘡縐嶉兘瑕佸啓涓猳p錛岄偅瑕乴ambda浣曠敤 錛夛紵op鐩稿綋浜庢眹緙栵紝鍙鍑犱釜綆鍗曠殑榪愮畻灝監K錛屽叧閿湪浜庢寜鐓lace_holder鐨勮〃杈撅紝鎶妎p緇勫悎璧鋒潵銆?br><br>涓嬩竴綃囧噯澶囦粙緇嶄竴涓媌oost::tuple錛屽拰琛ㄨ揪寮忕紪璇戯紝鍥犱負瀹冧滑鏄疄鐜發ambda鐨勫叧閿鍣ㄣ?<img src ="http://www.shnenglu.com/yindf/aggbug/74616.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/yindf/" target="_blank">灝逛笢鏂?/a> 2009-02-22 22:11 <a href="http://www.shnenglu.com/yindf/articles/74616.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>娣卞叆鎺㈢儲 boost::lambda 緋誨垪錛堜簩錛?/title><link>http://www.shnenglu.com/yindf/articles/74444.html</link><dc:creator>灝逛笢鏂?/dc:creator><author>灝逛笢鏂?/author><pubDate>Fri, 20 Feb 2009 11:21:00 GMT</pubDate><guid>http://www.shnenglu.com/yindf/articles/74444.html</guid><wfw:comment>http://www.shnenglu.com/yindf/comments/74444.html</wfw:comment><comments>http://www.shnenglu.com/yindf/articles/74444.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.shnenglu.com/yindf/comments/commentRss/74444.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/yindf/services/trackbacks/74444.html</trackback:ping><description><![CDATA[<p>涓婃璇村埌鍦ㄥ亣璁劇被鍨媔nt涓嬶紝鎴愬姛鐨勫疄鐜頒簡涓涓?#8220;lambda”錛岃繖嬈★紝褰撶劧涓嶈兘榪樺湪int鐨勫亣璁句笅浜嗐傛垜浠殑姝﹀櫒灝辨槸妯℃澘錛岃璧鋒潵妯℃澘錛岃瘽灝遍暱浜嗐?br>榪欓噷鐣ヨ繃錛岃閲嶇偣銆?/p> <p>榪欐槸涓婃鏈鍚庣殑浠g爜錛屼負浜嗘柟渚挎弿榪幫紝鍐嶈創涓浠姐?br></p> <div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080"> 1</span> <span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000"> op<br></span><span style="COLOR: #008080"> 2</span> <span style="COLOR: #000000">{<br></span><span style="COLOR: #008080"> 3</span> <span style="COLOR: #000000">    op(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i)<br></span><span style="COLOR: #008080"> 4</span> <span style="COLOR: #000000">        : _i(i)<br></span><span style="COLOR: #008080"> 5</span> <span style="COLOR: #000000">    {}<br></span><span style="COLOR: #008080"> 6</span> <span style="COLOR: #000000"><br></span><span style="COLOR: #008080"> 7</span> <span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> _i;<br></span><span style="COLOR: #008080"> 8</span> <span style="COLOR: #000000"><br></span><span style="COLOR: #008080"> 9</span> <span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">operator</span><span style="COLOR: #000000">()(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000"> i)<br></span><span style="COLOR: #008080">10</span> <span style="COLOR: #000000">    {<br></span><span style="COLOR: #008080">11</span> <span style="COLOR: #000000">        i </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> _i;<br></span><span style="COLOR: #008080">12</span> <span style="COLOR: #000000">    }<br></span><span style="COLOR: #008080">13</span> <span style="COLOR: #000000">};<br></span><span style="COLOR: #008080">14</span> <span style="COLOR: #000000"><br></span><span style="COLOR: #008080">15</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000"> place_holder<br></span><span style="COLOR: #008080">16</span> <span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">17</span> <span style="COLOR: #000000">    op </span><span style="COLOR: #0000ff">operator</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i)<br></span><span style="COLOR: #008080">18</span> <span style="COLOR: #000000">    {<br></span><span style="COLOR: #008080">19</span> <span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> op(i)<br></span><span style="COLOR: #008080">20</span> <span style="COLOR: #000000">    }<br></span><span style="COLOR: #008080">21</span> <span style="COLOR: #000000">};<br></span><span style="COLOR: #008080">22</span> <span style="COLOR: #000000"><br></span><span style="COLOR: #008080">23</span> <span style="COLOR: #000000">place_holder _1;<br></span><span style="COLOR: #008080">24</span> <span style="COLOR: #000000"><br></span><span style="COLOR: #008080">25</span> <span style="COLOR: #000000">for_each(v.begin(), v.end(), _1 </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">);</span></div> <p><br>瑕佸幓鎺夊int鐨勪緷璧栵紝鍏堜粩緇嗘兂鎯沖int鐨勪緷璧栭兘鍦ㄥ摢閲岋紵璇存槑鐧界偣灝辨槸鏁翠釜紼嬪簭錛屽摢閲岄兘鏈塱nt錛?br>1.  op鐨勬瀯閫犲嚱鏁板弬鏁版槸int<br>2.  op閲岄潰鐨勬垚鍛樺彉閲?_i鐨勭被鍨嬫槸int<br>3.  op鐨刼perator() 鐨勮繑鍥炲煎拰鍙傛暟閮芥湁int<br>4.  place_holder鐨刼perator=鐨勫弬鏁版槸int</p> <p>褰撶劧 vector<int> 涔熸湁int錛屼絾榪欎釜涓嶇畻 錛氾級</p> <p>鎬葷殑鏉ヨ錛宨nt鍜?涓涓彉閲?int op::_i錛?涓変釜鍑芥暟 op::op(int i), op::operaator(int& i) 鍜?place_holder::operator=(int) 鏈夊叧緋伙紝榪欎竴鐐瑰緢閲嶈錛岀被鍜屽嚱鏁板湪娉涘瀷涓殑浣滅敤涓嶄竴鏍鳳紝<br>鐪嬬湅 <a href="http://www.shnenglu.com/yindf/archive/2009/02/20/74397.html">http://www.shnenglu.com/yindf/archive/2009/02/20/74397.html</a> 涓鐨勭被妯℃澘鍜屽嚱鏁版ā鏉跨殑鍖哄埆鍚с?/p> <p>鍐嶇粏鍒嗕竴鐐癸紝鍜?_1 鏈夊叧鐨刬nt灝卞彧鏈塷p::operator()涓涓紝鍏朵粬閮藉拰 _1 娌″叧緋匯?br>鍓╀笅鐨勯兘鍜?3 鏈夊叧緋伙紝鎯蟲兂 3 鐨勪紶閫掕礬寰勶紝 浠?place_holder::operator = 鍒?op::op(int i)錛?鍐嶅埌 op::_i銆?/p> <p>涔熷氨鏄op::operator()瑕佷竴涓嫭绔嬬殑妯℃澘鍙傛暟銆?br>鎯蟲兂鐪嬶紝鍏跺疄op::op(int i) 鍜?op::_i 鏄竴涓笢瑗匡紝鏋勯犲嚱鏁板氨鏄負浜嗗垵濮嬪寲榪欎釜鍙橀噺銆傛墍浠ヨ繖閲岄夋嫨娉涘寲鏁翠釜op錛屽氨鏄鏋勯犲嚱鏁扮殑鍙傛暟鍜屽彉閲忔槸鍚屼竴涓被鍨嬨?br>瀵逛簬place_holder::operator =錛?鏄娉涘寲鏁翠釜place_holder鍛紝榪樻槸鍙硾鍖杙lace_holder::operator=鍛紝褰撶劧娉涘寲鍑芥暟錛屽洜涓虹被涓嶄細榪涜綾誨瀷鎺ㄥ銆?br>鎰忔濇槸濡傛灉娉涘寲綾葷殑璇濓紝浣犲氨瑕佹湁涓烘棤鏁扮被鍨嬬壒鍖栬繃鐨刾lace_holder錛岃繖閲屽緢闅劇悊瑙o紝涓嶇悊瑙g殑璇濓紝緇х畫鐪嬩笅鍘誨惂銆?/p> <p>鐜板湪灝卞紑濮嬪疄鍋氬惂銆?br><br></p> <div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080"> 1</span> <span style="COLOR: #000000">template </span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">typename _U</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080"> 2</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000"> op<br></span><span style="COLOR: #008080"> 3</span> <span style="COLOR: #000000">{<br></span><span style="COLOR: #008080"> 4</span> <span style="COLOR: #000000">    op(_U i)<br></span><span style="COLOR: #008080"> 5</span> <span style="COLOR: #000000">        : _i(i)<br></span><span style="COLOR: #008080"> 6</span> <span style="COLOR: #000000">    {}<br></span><span style="COLOR: #008080"> 7</span> <span style="COLOR: #000000"><br></span><span style="COLOR: #008080"> 8</span> <span style="COLOR: #000000">    _U _i;<br></span><span style="COLOR: #008080"> 9</span> <span style="COLOR: #000000"><br></span><span style="COLOR: #008080">10</span> <span style="COLOR: #000000">    template</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">typename _T</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">11</span> <span style="COLOR: #000000">    _T</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">operator</span><span style="COLOR: #000000">()(_T</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000"> i)<br></span><span style="COLOR: #008080">12</span> <span style="COLOR: #000000">    {<br></span><span style="COLOR: #008080">13</span> <span style="COLOR: #000000">        i </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> _i;<br></span><span style="COLOR: #008080">14</span> <span style="COLOR: #000000">    }<br></span><span style="COLOR: #008080">15</span> <span style="COLOR: #000000">};<br></span><span style="COLOR: #008080">16</span> <span style="COLOR: #000000"><br></span><span style="COLOR: #008080">17</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000"> place_holder<br></span><span style="COLOR: #008080">18</span> <span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">19</span> <span style="COLOR: #000000">    template </span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">typename _T</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">20</span> <span style="COLOR: #000000">    op</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">_T</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">operator</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">(_T i)<br></span><span style="COLOR: #008080">21</span> <span style="COLOR: #000000">    {<br></span><span style="COLOR: #008080">22</span> <span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> op</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">_T</span><span style="COLOR: #000000">></span><span style="COLOR: #000000">(i)<br></span><span style="COLOR: #008080">23</span> <span style="COLOR: #000000">    }<br></span><span style="COLOR: #008080">24</span> <span style="COLOR: #000000">};<br></span><span style="COLOR: #008080">25</span> <span style="COLOR: #000000"><br></span><span style="COLOR: #008080">26</span> <span style="COLOR: #000000">place_holder _1;<br></span><span style="COLOR: #008080">27</span> <span style="COLOR: #000000"><br></span><span style="COLOR: #008080">28</span> <span style="COLOR: #000000">for_each(v.begin(), v.end(), _1 </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">);</span></div> <p><br>濂戒簡錛屾硾鍖栧畬鎴愩傞毦閬撳氨榪欎箞綆鍗曪紵浜嬪疄灝辨槸榪欎箞綆鍗曘?br>鏉ュ垎鏋愪竴涓嬫ā鏉挎帹瀵肩殑榪囩▼鍚э紝  _1 = 3 璋冪敤錛屼粠涓嬮潰榪欎釜鍑芥暟寮濮嬶紝<br></p> <div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080">1</span> <span style="COLOR: #000000">template </span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">typename _T</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">2</span> <span style="COLOR: #000000">op</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">_T</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"> place_holder::</span><span style="COLOR: #0000ff">operator</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">(_T i);</span></div> <p><br>閭d箞榪欎釜_T 琚帹瀵間負 int, 鐒跺悗榪斿洖涓涓?op<int>, 鐒跺悗 op<int> 閲岄潰灝辨湁涓涓?int op<int>::_i;</p> <p>浜庢槸錛屽湪for_each閲岄潰錛岀浉褰撲簬鏈夎繖涔堜竴鍙ワ細<br></p> <div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080">1</span> <span style="COLOR: #000000">op</span><span style="COLOR: #000000"><</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"> p;<br></span><span style="COLOR: #008080">2</span> <span style="COLOR: #000000">p(</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">iter);</span></div> <br>op鐨勬ā鏉垮弬鏁拌鎺ㄥ畾涔変負int浜嗭紙涓嶆槸鎺ㄥ鐨勶紝綾繪ā鏉夸笉浼氭帹瀵鹼級銆?br><br>鎵浠ユ墜娉曟槸<strong>鍏堥潬鍑芥暟鎺ㄥ妯℃澘鍙傛暟錛屽啀闈犵被淇濆瓨綾誨瀷淇℃伅銆?br><br></strong>浜庢槸錛屼笅闈㈢殑鍑芥暟妯℃澘<br><br> <div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080">1</span> <span style="COLOR: #000000">template</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">typename _T</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">2</span> <span style="COLOR: #000000">_T</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000"> op</span><span style="COLOR: #000000"><</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">></span><span style="COLOR: #000000">::</span><span style="COLOR: #0000ff">operator</span><span style="COLOR: #000000">()(_T</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000"> i)<br></span><span style="COLOR: #008080">3</span> <span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">4</span> <span style="COLOR: #000000">    i </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> _i;<br></span><span style="COLOR: #008080">5</span> <span style="COLOR: #000000">}</span></div> <p><br>鐨勬ā鏉垮弬鏁?_T 灝辮鎺ㄥ鎴?*iter 鐨勭被鍨嬩簡錛屼篃灝辨槸瀹瑰櫒鐨?value_type 浜嗐?/p> <p>濂戒簡錛屽埌鐜板湪錛屼竴涓祴鍊肩殑lambda灝卞仛濂戒簡錛屽畠榪樿兘榪欎箞鐢細</p> <div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080">1</span> <span style="COLOR: #0000ff">double</span><span style="COLOR: #000000"> x;<br></span><span style="COLOR: #008080">2</span> <span style="COLOR: #000000">(_1 </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">)(x);</span></div> <p>灝辯粰x璧嬪?浜嗭紝紲炲鍚с?br>鍥犱負  (_1 = 5)榪斿洖鐨勬槸涓猯ambda琛ㄨ揪寮忥紝涔熷氨鏄釜浠垮嚱鏁幫紝:)<br></p> <p>鐜板湪鎵嶇湅鍒發ambda鏍稿績鐨勪竴灝忛儴鍒嗭紝宸茬粡璁╀漢鎰熻鐪╂檿浜嗐?br>鐪嬬湅鐜板湪榪樺瓨鍦ㄧ殑闂錛屽彧瀹炵幇浜嗕竴涓祴鍊兼搷浣滐紝鍏朵粬鐨勫憿錛?涓嬬瘒緇х畫銆傘傘?/p> <img src ="http://www.shnenglu.com/yindf/aggbug/74444.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/yindf/" target="_blank">灝逛笢鏂?/a> 2009-02-20 19:21 <a href="http://www.shnenglu.com/yindf/articles/74444.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>娣卞叆鎺㈢儲 boost::lambda 緋誨垪 錛堜竴錛?/title><link>http://www.shnenglu.com/yindf/articles/74319.html</link><dc:creator>灝逛笢鏂?/dc:creator><author>灝逛笢鏂?/author><pubDate>Thu, 19 Feb 2009 11:19:00 GMT</pubDate><guid>http://www.shnenglu.com/yindf/articles/74319.html</guid><wfw:comment>http://www.shnenglu.com/yindf/comments/74319.html</wfw:comment><comments>http://www.shnenglu.com/yindf/articles/74319.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/yindf/comments/commentRss/74319.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/yindf/services/trackbacks/74319.html</trackback:ping><description><![CDATA[<font style="FONT-FAMILY: courier new" face=#ce_temp_font#><br>鍒氭敞鍐屽ソcppblog鐨勭敤鎴鳳紝榪欑畻鏄濂充綔浜嗐?鏈榪戝湪瀛︿範boost::lambda, 鍒嗕韓涓嬪涔犲績寰楋紝鍏卞悓榪涙銆?br><br>褰撶劧榪欑瘒涓嶆槸璁瞓oost::lambda鐨勭敤娉曠殑錛屽鏈夋湁浜烘劅鍏磋叮錛屽彲浠ュ弬鐓э細<a >http://www.boost.org/doc/libs/1_38_0/doc/html/lambda.html</a><br><br>boost::lambda寰堝鏉傦紝涓涓ゅ彞璇濅篃璇翠笉娓呮錛屾垜灝藉姏鎻忚堪鐨勭畝鍗曚竴鐐癸紝鎱㈡參澧炲姞闅懼害銆?br><br>瀵規垜鏉ヨ錛宐oost::lambda鐪佷簡涓嶅皯浜嬶紝鎴戞槸鍠滄stl algorithm鐨勶紝鐜板湪鍩烘湰涓婇櫎闈炵壒孌婃儏鍐碉紝紼嬪簭閲岄潰閮戒笉鍑虹幇寰幆浜嗐傜敤for_each, transform 絳夌瓑閮藉彲浠ユ悶瀹氾紝鍚﹀垯錛屽氨瑕佽冭檻鏁版嵁緇撴瀯鍜岀畻娉曟槸涓嶆槸鏈夐棶棰樹簡銆?br><br>浣嗘槸闂鍦ㄤ簬姣忔鐢╢or_each鐨勬椂鍊欙紝閮借瀹氫箟涓涓豢鍑芥暟錛圡odern C++ Design 榪欎箞鍙殑錛夛紝楹葷儲錛岀▼搴忕湅璧鋒潵涔熶笉鎬庝箞浼橀泤欏虹晠錛屾昏鍋滀笅鏉ュ幓鐪嬮偅涓豢鍑芥暟鍒板簳騫蹭粈涔堜簡錛屽啓鐨勬椂鍊欒繕瑕佹兂鏄笉鏄娉涘寲錛屽緢澶寸棝銆傛湁浜哹oost::lambda錛屽氨鐖藉浜嗐傜湅璧鋒潵涓鐩簡鐒訛紝鍐欒搗鏉ョ畝鍗曟槑浜嗭紝涓嶇敤鍏沖績綾誨瀷銆傦紙鏄笉鏄悶鎺ㄩ攢鐨勶紵錛?br><br>璦褰掓浼犲惂銆?br><br>姣斿涓嬮潰榪欐浠g爜錛?br><br> <div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080"> 1</span> <span style="COLOR: #000000">vector</span><span style="COLOR: #000000"><</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"> v;<br></span><span style="COLOR: #008080"> 2</span> <span style="COLOR: #000000">v.push_back(</span><span style="COLOR: #000000">12</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080"> 3</span> <span style="COLOR: #000000">v.push_back(</span><span style="COLOR: #000000">1342</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080"> 4</span> <span style="COLOR: #000000">v.push_back(</span><span style="COLOR: #000000">23</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080"> 5</span> <span style="COLOR: #000000"><br></span><span style="COLOR: #008080"> 6</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000"> OP<br></span><span style="COLOR: #008080"> 7</span> <span style="COLOR: #000000">{<br></span><span style="COLOR: #008080"> 8</span> <span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">operator</span><span style="COLOR: #000000">()(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">&</span><span style="COLOR: #000000">i)<br></span><span style="COLOR: #008080"> 9</span> <span style="COLOR: #000000">    {<br></span><span style="COLOR: #008080">10</span> <span style="COLOR: #000000">        i </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">11</span> <span style="COLOR: #000000">    }<br></span><span style="COLOR: #008080">12</span> <span style="COLOR: #000000">};<br></span><span style="COLOR: #008080">13</span> <span style="COLOR: #000000"><br></span><span style="COLOR: #008080">14</span> <span style="COLOR: #000000">for_each(v.begin(), v.end(), OP());</span></div> </font><br>澶熺畝鍗曞惂錛屾妸鏁翠釜瀹瑰櫒鐨勫奸兘鏀規垚3. 鐪嬪埌閭d釜OP浜嗗惂錛屽緢綆鍗曠殑涓浠朵簨鎯咃紝闈炶璁╀漢鍐欒繖涔堜釜struct錛岃鏄啓鎴恈lass錛岃繕瑕乸ublic錛屾洿閮侀椃銆?br><br>鐪嬬湅鐢ㄤ簡boost::lambda浠ュ悗鐨勬晥鏋滃惂銆?br> <div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-FAMILY: courier new; HEIGHT: 110px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080">1</span> <span style="COLOR: #000000">vector</span><span style="COLOR: #000000"><</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"> v;<br></span><span style="COLOR: #008080">2</span> <span style="COLOR: #000000">v.push_back(</span><span style="COLOR: #000000">12</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">3</span> <span style="COLOR: #000000">v.push_back(</span><span style="COLOR: #000000">1342</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">4</span> <span style="COLOR: #000000">v.push_back(</span><span style="COLOR: #000000">23</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">5</span> <span style="COLOR: #000000"><br></span><span style="COLOR: #008080">6</span> <span style="COLOR: #000000">for_each(v.begin(), v.end(), _1 </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">7</span> <span style="COLOR: #000000"></span></div> <br>姣斾笉鐢╨ambda鏁存暣灝戜簡涓涓狾P瀹氫箟鍛錛屽洜涓?string("OP()").length() == string("_1=3").length() .<br><br>閭d箞錛屾庝箞鎵嶈兘杈懼埌榪欎釜鏁堟灉鍛紝鍦ㄨ繖閲岋紝鍏堝亣璁炬垜浠彧鐢╥nt綾誨瀷錛屽叧浜庢硾鍖栵紝涓嬩竴綃囧啀璇達紝涓嬈″悆澶氫簡娑堝寲涓嶈壇鐨勩?br><br>鐔熸倝for_each鐨勯兘鐭ラ亾錛宖or_each鐨勭3涓弬鏁版槸涓嚱鏁板璞★紙鎴戜笉鐢ㄦ寚閽堟姳姝夛級錛屾敞鎰忓尯鍒嗕豢鍑芥暟鍜屽嚱鏁板璞★紝浠垮嚱鏁版槸涓被鍨嬶紝鍑芥暟瀵硅薄鏄釜瀵硅薄銆?br><br>閭d箞涔熷氨鏄  _1 = 3 鐨勭粨鏋滃簲璇ユ槸涓嚱鏁板璞★紝鑰屼笖鏄釜涓鍏冨嚱鏁板璞★紙涓嶄簡瑙g殑鍘葷湅for_each瀹炵幇錛夈傜煡閬撲簡榪欎釜錛屽緢瀹規槗鍐欎釜澶ф錛?br><br> <div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080"> 1</span> <span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000"> op<br></span><span style="COLOR: #008080"> 2</span> <span style="COLOR: #000000">{<br></span><span style="COLOR: #008080"> 3</span> <span style="COLOR: #000000">    </span><span style="COLOR: #000000">???</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">operator</span><span style="COLOR: #000000">()(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000"> i)<br></span><span style="COLOR: #008080"> 4</span> <span style="COLOR: #000000">    {<br></span><span style="COLOR: #008080"> 5</span> <span style="COLOR: #000000">        i </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">???</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080"> 6</span> <span style="COLOR: #000000">    }<br></span><span style="COLOR: #008080"> 7</span> <span style="COLOR: #000000">};<br></span><span style="COLOR: #008080"> 8</span> <span style="COLOR: #000000"><br></span><span style="COLOR: #008080"> 9</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000"> place_holder<br></span><span style="COLOR: #008080">10</span> <span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">11</span> <span style="COLOR: #000000">    op </span><span style="COLOR: #0000ff">operator</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i)<br></span><span style="COLOR: #008080">12</span> <span style="COLOR: #000000">    {<br></span><span style="COLOR: #008080">13</span> <span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> op</span><span style="COLOR: #000000">???</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">14</span> <span style="COLOR: #000000">    }<br></span><span style="COLOR: #008080">15</span> <span style="COLOR: #000000">};<br></span><span style="COLOR: #008080">16</span> <span style="COLOR: #000000"><br></span><span style="COLOR: #008080">17</span> <span style="COLOR: #000000">place_holder _1;<br></span><span style="COLOR: #008080">18</span> <span style="COLOR: #000000"><br></span><span style="COLOR: #008080">19</span> <span style="COLOR: #000000">for_each(v.begin(), v.end(), _1 </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">);</span></div> <br>錛燂紵錛熶笉鏄貢鐮侊紝榪欓噷鍙槸鏆傛椂涓嶇煡閬撳啓浠涔堛?br>鎴戣榪囷紝榪欑瘒閲岄潰綾誨瀷閮芥槸int錛屼絾鏄偅涓?鎬庝箞澶勭悊鍛紝鏄庢樉瑕佷繚瀛樼殑浠垮嚱鏁伴噷闈㈠幓涔堬紝鎵浠ヤ笂闈㈢殑浠g爜榪涗竴姝ヤ慨鏀癸紝<br>涓狾P閲岄潰澧炲姞鍙橀噺錛屾潵淇濆瓨3錛屽嚱鏁拌繑鍥炲肩幇鍦ㄤ笉閲嶈錛屽氨鍐欐垚int鍚э紝浠ュ悗鏈夐棶棰樺啀璇淬?br>浜庢槸浠g爜鍙樻垚錛?br><br> <div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080"> 1</span> <span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000"> op<br></span><span style="COLOR: #008080"> 2</span> <span style="COLOR: #000000">{<br></span><span style="COLOR: #008080"> 3</span> <span style="COLOR: #000000">    op(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i)<br></span><span style="COLOR: #008080"> 4</span> <span style="COLOR: #000000">        : _i(i)<br></span><span style="COLOR: #008080"> 5</span> <span style="COLOR: #000000">    {}<br></span><span style="COLOR: #008080"> 6</span> <span style="COLOR: #000000"><br></span><span style="COLOR: #008080"> 7</span> <span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> _i;<br></span><span style="COLOR: #008080"> 8</span> <span style="COLOR: #000000"><br></span><span style="COLOR: #008080"> 9</span> <span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">operator</span><span style="COLOR: #000000">()(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000"> i)<br></span><span style="COLOR: #008080">10</span> <span style="COLOR: #000000">    {<br></span><span style="COLOR: #008080">11</span> <span style="COLOR: #000000">        i </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> _i;<br></span><span style="COLOR: #008080">12</span> <span style="COLOR: #000000">    }<br></span><span style="COLOR: #008080">13</span> <span style="COLOR: #000000">};<br></span><span style="COLOR: #008080">14</span> <span style="COLOR: #000000"><br></span><span style="COLOR: #008080">15</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000"> place_holder<br></span><span style="COLOR: #008080">16</span> <span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">17</span> <span style="COLOR: #000000">    op </span><span style="COLOR: #0000ff">operator</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i)<br></span><span style="COLOR: #008080">18</span> <span style="COLOR: #000000">    {<br></span><span style="COLOR: #008080">19</span> <span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> op(i)<br></span><span style="COLOR: #008080">20</span> <span style="COLOR: #000000">    }<br></span><span style="COLOR: #008080">21</span> <span style="COLOR: #000000">};<br></span><span style="COLOR: #008080">22</span> <span style="COLOR: #000000"><br></span><span style="COLOR: #008080">23</span> <span style="COLOR: #000000">place_holder _1;<br></span><span style="COLOR: #008080">24</span> <span style="COLOR: #000000"><br></span><span style="COLOR: #008080">25</span> <span style="COLOR: #000000">for_each(v.begin(), v.end(), _1 </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">);</span></div> <br>闂瑙e喅銆?br><br>鐪嬪埌榪欓噷錛屾暣涓▼搴忓凡緇忓彲浠ユ墽琛屼簡銆傛妸瀹瑰櫒鐨勫兼敼鎴?錛屾病闂鍚с?br><br>鏁寸墖鏂囩珷閮藉湪涓涓亣璁句箣涓嬶紝灝辨槸鍙敤int錛岄偅瑕佹槸涓嶇敤int鍛紝鎯呭喌灝卞鏉備竴鐐逛簡錛屼笅綃囧啀璁ㄨ銆?濡傛灉鐔熸倝template鐨勮瘽錛屼笅綃囧緢瀹規槗錛屽惁鍒欙紝澶嶄範鍜? <img src ="http://www.shnenglu.com/yindf/aggbug/74319.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/yindf/" target="_blank">灝逛笢鏂?/a> 2009-02-19 19:19 <a href="http://www.shnenglu.com/yindf/articles/74319.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <p>感谢您访问我们的网站,您可能还对以下资源感兴趣:</p> <a href="http://www.shnenglu.com/" title="精品视频久久久久">精品视频久久久久</a> <div class="friend-links"> </div> </div> </footer> <a href="http://www.0731car.com.cn" target="_blank">久久亚洲高清综合</a>| <a href="http://www.misuca.cn" target="_blank">精品久久久久中文字幕日本</a>| <a href="http://www.ditiewang.com.cn" target="_blank">久久精品国产亚洲AV电影</a>| <a href="http://www.13542350234.cn" target="_blank">欧美一区二区三区久久综合</a>| <a href="http://www.goomba.cn" target="_blank">69久久夜色精品国产69</a>| <a href="http://www.jkh7.cn" target="_blank">狠狠色综合久久久久尤物</a>| <a href="http://www.hotsw.com.cn" target="_blank">无码人妻久久一区二区三区蜜桃</a>| <a href="http://www.13gf.cn" target="_blank">国产免费久久精品99re丫y</a>| <a href="http://www.99j9.cn" target="_blank">人妻无码αv中文字幕久久</a>| <a href="http://www.wxwyx.cn" target="_blank">久久精品国产精品亚洲</a>| <a href="http://www.malmoarts.cn" target="_blank">亚洲午夜久久久久久噜噜噜</a>| <a href="http://www.uutools.cn" target="_blank">国产成人AV综合久久</a>| <a href="http://www.c825.cn" target="_blank">亚洲国产一成人久久精品</a>| <a href="http://www.fanerge.cn" target="_blank">色综合久久综精品</a>| <a href="http://www.mztkn.cn" target="_blank">久久人人爽人人爽人人片av麻烦</a>| <a href="http://www.yozang.cn" target="_blank">久久亚洲综合色一区二区三区</a>| <a href="http://www.07sn.cn" target="_blank">亚洲中文字幕伊人久久无码</a>| <a href="http://www.xinjian452858.cn" target="_blank">久久99国产精品久久99</a>| <a href="http://www.dbwlcom.cn" target="_blank">久久久久久国产a免费观看黄色大片 </a>| <a href="http://www.jrtz112.cn" target="_blank">人妻无码久久精品</a>| <a href="http://www.qcbijj.cn" target="_blank">久久久久国产精品三级网</a>| <a href="http://www.qzxqd.cn" target="_blank">国内精品久久久久久99蜜桃</a>| <a href="http://www.tbssyc.cn" target="_blank">欧美久久天天综合香蕉伊</a>| <a href="http://www.shedan.com.cn" target="_blank">狠色狠色狠狠色综合久久</a>| <a href="http://www.173ec.cn" target="_blank">久久精品国产亚洲AV蜜臀色欲 </a>| <a href="http://www.567uu.cn" target="_blank">国产69精品久久久久777</a>| <a href="http://www.businesscube.cn" target="_blank">亚洲精品国产第一综合99久久</a>| <a href="http://www.centralworld.cn" target="_blank">无码人妻少妇久久中文字幕蜜桃 </a>| <a href="http://www.jn928.cn" target="_blank">久久久无码一区二区三区</a>| <a href="http://www.davidgroup.com.cn" target="_blank">欧美日韩精品久久久免费观看</a>| <a href="http://www.funziot.cn" target="_blank">国产精品一久久香蕉产线看</a>| <a href="http://www.wirja9.cn" target="_blank">久久香蕉超碰97国产精品</a>| <a href="http://www.meng1.cn" target="_blank">久久天天躁狠狠躁夜夜躁2014</a>| <a href="http://www.forexpo.cn" target="_blank">色播久久人人爽人人爽人人片aV</a>| <a href="http://www.bisibbs.cn" target="_blank">91久久九九无码成人网站</a>| <a href="http://www.vcyw.cn" target="_blank">丰满少妇人妻久久久久久4</a>| <a href="http://www.4000261688.cn" target="_blank">国产亚洲欧美成人久久片</a>| <a href="http://www.o7xcp.cn" target="_blank">狠狠色婷婷综合天天久久丁香</a>| <a href="http://www.drxt.com.cn" target="_blank">AV色综合久久天堂AV色综合在</a>| <a href="http://www.cjubbs.cn" target="_blank">久久精品亚洲精品国产色婷</a>| <a href="http://www.silverprice.net.cn" target="_blank">99久久99久久精品国产片果冻 </a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>