锘??xml version="1.0" encoding="utf-8" standalone="yes"?>国产99精品久久,国产亚洲精久久久久久无码77777,国内精品伊人久久久久777http://www.shnenglu.com/lambdacpp/archive/2007/07/24/28688.html浜旂偣鍗?/dc:creator>浜旂偣鍗?/author>Tue, 24 Jul 2007 04:34:00 GMThttp://www.shnenglu.com/lambdacpp/archive/2007/07/24/28688.htmlhttp://www.shnenglu.com/lambdacpp/comments/28688.htmlhttp://www.shnenglu.com/lambdacpp/archive/2007/07/24/28688.html#Feedback0http://www.shnenglu.com/lambdacpp/comments/commentRss/28688.htmlhttp://www.shnenglu.com/lambdacpp/services/trackbacks/28688.html    涓鑸儏鍐典笅鍑芥暟鎸囬拡鍜屽嚱鏁板璞?functor)鏄彲浠ヤ簰鎹㈢殑,濡俿td::for_each鐨勭涓変釜鍙傛暟,浣嗘爣鍑嗗簱涓湁4涓嚱鏁伴厤鎺ュ櫒(not1,not2,bind1st,bind2nd)鏄笉鑳芥帴鍙楀嚱鏁版寚閽?蹇呴』浣跨敤std::ptr_fun灝嗗嚱鏁版寚閽堝皝瑁呮垚鍑芥暟瀵硅薄.榪樻湁涓縐嶆儏鍐墊槸鍑芥暟鎸囬拡鎸囧悜鐨勫嚱鏁扮殑鍙傛暟綾誨瀷涓庡嚱鏁版ā鏉塊渶瑕佺殑涓嶅尮閰?濡傛灉瑕侀氳繃for_each璋冪敤姣忎釜Iterator鐨勮В寮曠敤(dereference)鐨勫璞$殑鏌愪釜鎴愬憳鍑芥暟.鐩存帴浣跨敤璇稿ClassA::*member_func鐨勬垚鍛樺嚱鏁版寚閽堟樉鐒舵槸鎯沖綋鐒剁殑鍋氭硶,璋冪敤鐨勮娉曢兘涓嶄竴鑷?緇撴灉鏄竴澶у爢緙栬瘧閿欒淇℃伅.娌℃湁鍏崇郴鍙互浣跨敤std::mem_fun鍜宻td::mem_fun_ref.濡俧or_each(classAVector.begin(),classAVector.end(),mem_fun_ref(ClassA::*member_func)).鏍囧噯搴撲腑鐨勮繖涓濂楀嚱鏁伴傞厤鍣?functor adapters)浣跨敤璧鋒潵瑕佸厖鍒嗚冭檻浣跨敤鐨勫満鍚?涓嶅悓鐨勬儏鍐典嬌鐢ㄤ笉鍚岄厤鎺ュ櫒.鐗瑰埆鏄?zhèn)ㄨ鍖哄垎for_each鐨勫鍣ㄦ槸Container<T>榪樻槸Container<T*>,鍓嶈呬嬌鐢╯td::mem_fun_ref,鍚庤呬嬌鐢╯td::mem_fun.榪欎竴孌電殑璇︾粏璁ㄨ鍙竴鍙傜収Effective STL鐨勭40鏉″拰絎?1鏉?(涓漢鎰熻榪欏嚑涓厤鎺ュ櫒鐨勫悕瀛楃湡鏈夌殑...fun).
    濡傛灉鎮(zhèn)ㄥ疄鍦ㄦ槸鏈夌偣鍙椾笉浜?jiǎn)鎴栬呬綘涓嶈兘紜畾瀹瑰櫒涓┒绔熸斁鐨勬槸浠涔堣屼笖浣犳効鎰忎嬌鐢ㄤ竴涓嬪噯鏍囧噯搴?灝卞彲浠ヨ冭檻boost搴撶殑mem_fn.boost::mem_fn涔熶笉鏄緢鐗瑰埆鐨刡oost鎴愬憳.浣跨敤boost::mem_fn濂藉錛氫笉鐢ㄥ叧蹇?jī)瀹瑰櫒涓槸T榪樻槸T*鐢氳嚦鏄痓oost::share_ptr<T>,鍙﹀涔頒竴璧犱竴fn姣攆un鏇村ソ鍚竴鐐?涓嬮潰鎶勫綍boost鐨勫府鍔╀唬鐮佸氨寰堣鏄庨棶棰樹簡(jiǎn).
struct X
{
    
void f();
};

void g(std::vector<X> & v)
{
    std::for_each(v.begin(), v.end(), boost::mem_fn(
&X::f));
};

void h(std::vector<*> const & v)
{
    std::for_each(v.begin(), v.end(), boost::mem_fn(
&X::f));
};

void k(std::vector<boost::shared_ptr<X> > const & v)
{
    std::for_each(v.begin(), v.end(), boost::mem_fn(
&X::f));
};



]]>
灝唌ap涓殑鏁版嵁瀵煎叆鍒皏ector涓?/title><link>http://www.shnenglu.com/lambdacpp/archive/2006/10/23/14050.html</link><dc:creator>浜旂偣鍗?/dc:creator><author>浜旂偣鍗?/author><pubDate>Mon, 23 Oct 2006 13:57:00 GMT</pubDate><guid>http://www.shnenglu.com/lambdacpp/archive/2006/10/23/14050.html</guid><wfw:comment>http://www.shnenglu.com/lambdacpp/comments/14050.html</wfw:comment><comments>http://www.shnenglu.com/lambdacpp/archive/2006/10/23/14050.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.shnenglu.com/lambdacpp/comments/commentRss/14050.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/lambdacpp/services/trackbacks/14050.html</trackback:ping><description><![CDATA[瑕佸皢涓涓猰ap<T1,T2>涓殑鏁版嵁瀵煎叆鍒頒竴涓獀ector<T2>涓紝鍙互鑰冭檻浣跨敤鏍囧噯搴撲腑鐨則ransform,浣唌ap<T1,T2>::iterator涓巚ector<T2>::iterator鏄笉鍖歸厤鐨勶紝鍙椼奅ffective STL銆嬬20鏉″惎鍙戝啓涓猰ap2vector鐨刦unctor錛屽彲浠ヨВ鍐寵繖涓棶棰橈紙涓嶈繃榪欎釜榪樹笉綆楃湡姝g殑meta-programming錛夛細(xì)<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">#include聽</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">map</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br />#include聽</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">vector</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br />#include聽</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">iostream</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br />#include聽</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br />#include聽</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">iterator</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br /><br /></span><span style="color: rgb(0, 0, 255);">using</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 255);">namespace</span><span style="color: rgb(0, 0, 0);">聽std;<br /><br /></span><span style="color: rgb(0, 0, 255);">struct</span><span style="color: rgb(0, 0, 0);">聽map2vector<br />{<br />聽聽聽聽template</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">typename聽T</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br />聽聽聽聽</span><span style="color: rgb(0, 0, 255);">const</span><span style="color: rgb(0, 0, 0);">聽typename聽T::second_type</span><span style="color: rgb(0, 0, 0);">&</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 255);">operator</span><span style="color: rgb(0, 0, 0);">()(</span><span style="color: rgb(0, 0, 255);">const</span><span style="color: rgb(0, 0, 0);">聽T</span><span style="color: rgb(0, 0, 0);">&</span><span style="color: rgb(0, 0, 0);">聽p)<br />聽聽聽聽聽聽聽聽{<br />聽聽聽聽聽聽聽聽聽聽聽聽</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">聽p.second;<br />聽聽聽聽聽聽聽聽}<br />};<br /><br /><br /></span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">聽main()<br />{<br />聽聽聽聽map</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);">聽m;<br />聽聽聽聽vector</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);">聽v;<br /><br />聽聽聽聽m[</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">key1</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">]</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">sdf111</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br />聽聽聽聽m[</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">k2</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">]</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">sdf11</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br />聽聽聽聽m[</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">k3</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">]</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">sdf2</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br /><br />聽聽聽聽transform(m.begin(),m.end(),back_inserter(v),map2vector());<br />聽聽聽聽copy(v.begin(),v.end(),ostream_iterator</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);">(cout,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">\n</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));<br /></span><span style="color: rgb(0, 0, 255);">聽聽聽 return</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;<br />}<br /></span></div><br /><br /><img src ="http://www.shnenglu.com/lambdacpp/aggbug/14050.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/lambdacpp/" target="_blank">浜旂偣鍗?/a> 2006-10-23 21:57 <a href="http://www.shnenglu.com/lambdacpp/archive/2006/10/23/14050.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Boost搴撶殑formathttp://www.shnenglu.com/lambdacpp/archive/2006/05/25/7610.html浜旂偣鍗?/dc:creator>浜旂偣鍗?/author>Wed, 24 May 2006 17:46:00 GMThttp://www.shnenglu.com/lambdacpp/archive/2006/05/25/7610.htmlhttp://www.shnenglu.com/lambdacpp/comments/7610.htmlhttp://www.shnenglu.com/lambdacpp/archive/2006/05/25/7610.html#Feedback0http://www.shnenglu.com/lambdacpp/comments/commentRss/7610.htmlhttp://www.shnenglu.com/lambdacpp/services/trackbacks/7610.html
  1. 瀹氫箟涓涓猣ormat綾伙紝騫舵寚瀹氬瓧絎︿覆鐨勫悇寮?鐩稿綋浜巔rintf鐨勭涓涓弬鏁?
    • boost::format fs("Test String:%s,%d");
  2. 閫氳繃%榪愮畻絎﹀甫鍏ュ弬鏁?%s琛ㄧず瀛楃涓?%d琛ㄧず鏁存暟,涓巔rintf闈炲父綾諱技)
    • fs%"string"%121;
  3. 閫氳繃<<杈撳嚭(format閲嶈澆浜?lt;<榪愮畻絎?鎴栭氳繃str()鍑芥暟鑾峰彇緇撴灉
    • std::cout<<fs; //杈撳嚭Test String:string,121
    • std::string result = fs.str();
涓浜涘嚱鏁?
  • str() 鑾峰彇緇撴灉瀛楃涓?/li>
  • clear() 娓呯┖宸茬粡甯﹀叆鐨勫弬鏁?/li>
  • parse(str::string s)娓呯┖宸茬粡甯﹀叆鐨勫弬鏁?騫跺皢s鍔犲湪鍚勫紡瀛楃涓蹭箣鍚?/li>
鏈変竴鐐硅娉ㄦ剰:鍦ㄨ幏鍙栫粨鏋滃瓧絎︿覆鎴?lt;<杈撳嚭鏃跺弬鏁頒竴瀹氳瀹屾暣甯﹀叆,涓嶇劧灝嗘姏鍑哄紓甯搞?br />
姝ゅ浠呬粎鎶涚爾寮曠帀錛屽瑕佷嬌鐢ㄨ鍙傝?http://www.boost.org/libs/format/doc/format.html



]]>
C++涓殑typename鍏抽敭瀛?鎯沖摢鍎胯鍝効)http://www.shnenglu.com/lambdacpp/archive/2006/05/25/7607.html浜旂偣鍗?/dc:creator>浜旂偣鍗?/author>Wed, 24 May 2006 17:16:00 GMThttp://www.shnenglu.com/lambdacpp/archive/2006/05/25/7607.htmlhttp://www.shnenglu.com/lambdacpp/comments/7607.htmlhttp://www.shnenglu.com/lambdacpp/archive/2006/05/25/7607.html#Feedback0http://www.shnenglu.com/lambdacpp/comments/commentRss/7607.htmlhttp://www.shnenglu.com/lambdacpp/services/trackbacks/7607.htmltemplate<class T>
class Test
{
聽 聽 public :
聽 聽 聽聽 T t;
聽 聽 .....
};
闅忕潃妯℃澘搴旂敤鐨勬帹騫匡紝澶у鍙戠幇浣跨敤typedef闈炲父鍏抽敭錛屽洜涓哄疄渚嬪寲鍚庣殑妯℃澘瀹氫箟閫氬父寰堥暱錛岄氳繃浣跨敤typedef鍙互鏈夋晥鐨勭緝鐭唬鐮侀暱搴︺傚:
class UseTest
{
public:
聽聽聽 typedef Test<int> intTT;
聽聽聽 ...
};
榪欐椂闂灝辨潵浜?褰撴垜鍐橴seTest::intTT錛岃繖涓猧ntTT絀剁珶鏄疷seTest鐨勪竴涓潤(rùn)鎬佹垚鍛?static)榪樻槸涓涓被鍨嬪憿錛熸墍浠ypename鍏抽敭瀛楀氨寮曞叆浜?jiǎn)C++銆?br />鎵浠ュ湪瀹氫箟涓涓猧ntTT鐨勫璞℃椂,鎴戜滑灝辮榪欐牱鍐?
聽 typename UseTest::intTT int_tt_obj;
閫氳繃typename鏄庣‘鎸囧嚭intTT鏄竴涓被鍨嬭屼笉鏄竴涓潤(rùn)鎬佹垚鍛樸?br />



]]>
国产真实乱对白精彩久久| 亚洲人成无码网站久久99热国产| 天天综合久久一二三区| 久久久久国产一区二区三区| 婷婷久久精品国产| 免费久久人人爽人人爽av| 亚洲国产精品无码久久SM| 久久综合丁香激情久久| 久久青青草原精品国产软件| 亚洲精品无码久久久久sm| 免费精品99久久国产综合精品| 人妻中文久久久久| 色欲久久久天天天综合网精品| 久久精品国产99国产电影网 | 久久99热这里只有精品国产| 欧美精品福利视频一区二区三区久久久精品| 久久中文字幕人妻熟av女| 久久国产精品一区二区| 国内高清久久久久久| 久久婷婷五月综合97色直播| 99精品国产在热久久无毒不卡| 久久影视综合亚洲| 久久精品嫩草影院| 久久久一本精品99久久精品66| 亚洲国产精品综合久久网络 | 午夜肉伦伦影院久久精品免费看国产一区二区三区 | 囯产极品美女高潮无套久久久| 国产精品VIDEOSSEX久久发布| 国产三级久久久精品麻豆三级 | Xx性欧美肥妇精品久久久久久| 亚洲精品无码久久久影院相关影片| 久久久久国产成人精品亚洲午夜| 高清免费久久午夜精品| 久久精品国产亚洲αv忘忧草| 亚洲国产成人精品91久久久| 久久国产午夜精品一区二区三区| 99久久精品这里只有精品| 国产精品久久影院| 狠狠狠色丁香婷婷综合久久五月 | 97久久香蕉国产线看观看| 久久精品国产亚洲AV不卡|