锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲精品中文字幕在线,欧美区日韩区,久久人人爽人人爽http://m.shnenglu.com/kesalin/category/3832.html鍏蟲敞宓屽叆寮忔搷浣滅郴緇燂紝縐誨姩騫沖彴錛屽浘褰㈠紑鍙戙?lt;a target="_top">-->鍔犲井鍗?^_^</a>zh-cnThu, 10 Jul 2014 19:03:32 GMTThu, 10 Jul 2014 19:03:32 GMT60濡備綍鍦ㄩ亶鍘嗕腑浣跨敤 iterator/reverse_iterator 鍒犻櫎鍏冪礌http://m.shnenglu.com/kesalin/archive/2014/07/10/cpp_stl.html緗楁湞杈?/dc:creator>緗楁湞杈?/author>Thu, 10 Jul 2014 01:42:00 GMThttp://m.shnenglu.com/kesalin/archive/2014/07/10/cpp_stl.htmlhttp://m.shnenglu.com/kesalin/comments/206672.htmlhttp://m.shnenglu.com/kesalin/archive/2014/07/10/cpp_stl.html#Feedback1http://m.shnenglu.com/kesalin/comments/commentRss/206672.htmlhttp://m.shnenglu.com/kesalin/services/trackbacks/206672.html棣栧厛錛岃鏄庣櫧浣跨敤姝e悜榪唬鍣紙iterator錛夎繘琛屽弽鍚戦亶鍘嗘槸閿欒鐨勭敤娉曪紝瑕佷笉騫插槢瑕佹湁鍙嶅悜榪唬鍣ㄥ憿錛坮everse_iterator錛夈傚叾嬈★紝鏍規嵁瀹瑰櫒鐨勭壒鎬э紝閬嶅巻鍒犻櫎鎿嶄綔鐨勭敤娉曞彲浠ュ垎涓轟袱緇勶紝絎竴緇勬槸 list 鍜?vector錛岀浜岀粍鏄?map 鍜?set銆?nbsp; 闃呰鍏ㄦ枃

]]>
璁ゞcc鏀寔鎴愬憳鍑芥暟妯℃澘鐨則rickhttp://m.shnenglu.com/kesalin/archive/2013/07/12/gcc_member_function_template.html緗楁湞杈?/dc:creator>緗楁湞杈?/author>Fri, 12 Jul 2013 14:04:00 GMThttp://m.shnenglu.com/kesalin/archive/2013/07/12/gcc_member_function_template.htmlhttp://m.shnenglu.com/kesalin/comments/201753.htmlhttp://m.shnenglu.com/kesalin/archive/2013/07/12/gcc_member_function_template.html#Feedback2http://m.shnenglu.com/kesalin/comments/commentRss/201753.htmlhttp://m.shnenglu.com/kesalin/services/trackbacks/201753.html璁ゞcc鏀寔鎴愬憳鍑芥暟妯℃澘鐨則rick

緗楁湞杈?(http://m.shnenglu.com/kesalin/)

gcc 4.7.3 涓嶆敮鎸佹垚鍛樺嚱鏁版ā鏉跨壒鍖栥傚涓嬩唬鐮侊細

#ifndef __MEMFUNTEMPLATE_H__
#define __MEMFUNTEMPLATE_H__

#include <stdio.h>

class Base {};
class Derived : public Base {};

struct Functor {
    template <typename T> void function() {
        printf(" Primary template.\n");
    }

    template<>
    void function<int>(){
        printf(" Specialization for int.\n");
    }

    template<> void function<Base *>() {
        printf(" Specialization for Base *.\n");
    }
};

class Tester {
public:
    static void DoTest()
    {
        Functor functor;
        functor.function<char>();
        functor.function<int>();
        functor.function<Base *>();
        functor.function<Derived *>();
    }
};

#endif // __MEMFUNTEMPLATE_H__

鍦?VS2010 涓紪璇戣繍琛屾槸娌℃湁闂鐨勶紝浣嗗湪 gcc 4.7.3涓嬶紝緙栬瘧閮介氫笉榪囷細


涓轟簡杈懼埌榪戜技鎴愬憳鍑芥暟妯℃澘鐗瑰寲鐨勬晥鏋滐紝鍙互鍒╃敤鎴愬憳鍑芥暟涓繪ā鏉夸互鍙婇噸杞藉嚱鏁版潵瀹炵幇錛?br />


/*
 * MemFunTemplate.h
 *
 *  Created on: Jul 12, 2013
 *      Author: http://blog.csdn.net/kesalin/
 */

#ifndef MEMFUNTEMPLATE_H_
#define MEMFUNTEMPLATE_H_
#include <stdio.h>
template<typename T>
struct DummyIdentity {
    typedef T type;
};
class Base {};
class Derived : public Base {};
struct Functor {
    template <typename T> void function() {
        function(DummyIdentity<T>());
    }
private:
    template <typename T>
    void function(DummyIdentity<T>) {
        printf(" Primary template DummyIdentity<T>.\n");
    }
    void function(DummyIdentity<int>) {
        printf(" overload function for DummyIdentity<int>.\n");
    }
    void function(DummyIdentity<Base *>) {
        printf(" overload function for DummyIdentity<Base *>.\n");
    }
};
class Tester {
public:
    static void DoTest()
    {
        Functor functor;
        functor.function<char>();
        functor.function<int>();
        functor.function<Base *>();
        functor.function<Derived *>();
    }
};
#endif /* MEMFUNTEMPLATE_H_ */


璋冪敤 DoTest() 榪愯緇撴灉濡備笅錛?/p>


娉ㄦ剰錛?/span>

VS2010 鐗堟湰鐨勪唬鐮侊紝妯℃澘褰㈠弬涓?T錛屽湪瀹炰緥鍖栦笉浼氳繘琛岄殣寮忕被鍨嬭漿鎹€傚嵆鐢?nbsp;Derived * 褰撲綔瀹炲弬璋冪敤鐨勬槸涓繪ā鏉匡紝鑰屼笉鏄?Base * 鐗瑰寲鐗堟湰

鑰屽湪 gcc  涓嬶紝妯℃澘褰㈠弬铏界劧涔熶負T錛屼絾褰卞搷閲嶈澆鍐寵鐨?function 鍙傛暟涓猴細DummyIdentity<T>錛岀敤涓嶅悓鐨勫疄闄呭弬鏁板疄渚嬪寲璇ユā鏉匡紝寰楀埌鐨勬槸涓鍫嗛噸杞藉嚱鏁般傚洜姝ょ敤 Derived * 褰撲綔瀹炲弬鏃訛紝璋冪敤鐨勫嚱鏁拌嚜鐒跺氨鏄疄渚嬪寲鐨?nbsp;void function(DummyIdentity<T>)浜嗐?/p>



]]>
[娣卞叆鐞嗚ВC++錛堜簩錛塢鐞嗚В鎺ュ彛緇ф壙瑙勫垯http://m.shnenglu.com/kesalin/archive/2012/11/06/interface_inherit.html緗楁湞杈?/dc:creator>緗楁湞杈?/author>Tue, 06 Nov 2012 13:21:00 GMThttp://m.shnenglu.com/kesalin/archive/2012/11/06/interface_inherit.htmlhttp://m.shnenglu.com/kesalin/comments/194777.htmlhttp://m.shnenglu.com/kesalin/archive/2012/11/06/interface_inherit.html#Feedback5http://m.shnenglu.com/kesalin/comments/commentRss/194777.htmlhttp://m.shnenglu.com/kesalin/services/trackbacks/194777.html錛堜竴錛夛紝C++ 铏氬嚱鏁拌〃瑙f瀽
錛堜簩錛夛紝C++ 瀵硅薄鐨勫唴瀛樺竷灞錛堜笂錛?
錛堜笁錛夛紝C++ 瀵硅薄鐨勫唴瀛樺竷灞錛堜笅錛?

鍦ㄧ戶緇槄璇繪湰鏂囦箣鍓嶏紝寤鴻鍏堥槄璇昏繖涓夌瘒鏂囩珷錛屼互鏇村ソ鍦扮悊瑙f湰緋誨垪鏂囩珷銆傚湪鎺ヤ笅鏉ョ殑鍐呭涓紝鎴戝皢浠庨噸杞斤紝閲嶅啓錛屽睆钄界瓑姒傚康鍏ユ墜錛屽紩鍏ヤ紬澶氭帴鍙g戶鎵胯鍒欍?nbsp; 闃呰鍏ㄦ枃

]]>
[娣卞叆鐞嗚ВC++錛堜竴錛塢綾誨瀷杞崲錛圱ype Casting錛?/title><link>http://m.shnenglu.com/kesalin/archive/2012/10/28/type_cast.html</link><dc:creator>緗楁湞杈?/dc:creator><author>緗楁湞杈?/author><pubDate>Sun, 28 Oct 2012 13:44:00 GMT</pubDate><guid>http://m.shnenglu.com/kesalin/archive/2012/10/28/type_cast.html</guid><wfw:comment>http://m.shnenglu.com/kesalin/comments/193986.html</wfw:comment><comments>http://m.shnenglu.com/kesalin/archive/2012/10/28/type_cast.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://m.shnenglu.com/kesalin/comments/commentRss/193986.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/kesalin/services/trackbacks/193986.html</trackback:ping><description><![CDATA[     鎽樿: 綾誨瀷杞崲灝辨槸灝嗙粰瀹氱被鍨嬬殑琛ㄨ揪寮忚漿鎹負鍙︿竴縐嶇被鍨嬨侰++涓殑杞瀷鍙垎涓轟袱縐嶏細闅愬紡綾誨瀷杞崲鍜屾樉寮忕被鍨嬭漿鎹€備笅闈㈠皢璇︾粏浠嬬粛榪欎袱縐嶈漿鍨嬫搷浣滐紝浠ュ強鍚勮嚜鐨勯傜敤鍦烘櫙錛屾綔鍦ㄩ棶棰橈紝鏈緇堝皢鎬葷粨浣跨敤綾誨瀷杞崲鎿嶄綔搴旂墷璁扮殑鍘熷垯銆?nbsp; <a href='http://m.shnenglu.com/kesalin/archive/2012/10/28/type_cast.html'>闃呰鍏ㄦ枃</a><img src ="http://m.shnenglu.com/kesalin/aggbug/193986.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/kesalin/" target="_blank">緗楁湞杈?/a> 2012-10-28 21:44 <a href="http://m.shnenglu.com/kesalin/archive/2012/10/28/type_cast.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>娣卞叆鍒嗘瀽Sleep(0)涓嶴leep(1)鐨勫尯鍒?/title><link>http://m.shnenglu.com/kesalin/archive/2012/10/11/Sleep.html</link><dc:creator>緗楁湞杈?/dc:creator><author>緗楁湞杈?/author><pubDate>Thu, 11 Oct 2012 12:04:00 GMT</pubDate><guid>http://m.shnenglu.com/kesalin/archive/2012/10/11/Sleep.html</guid><wfw:comment>http://m.shnenglu.com/kesalin/comments/193183.html</wfw:comment><comments>http://m.shnenglu.com/kesalin/archive/2012/10/11/Sleep.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://m.shnenglu.com/kesalin/comments/commentRss/193183.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/kesalin/services/trackbacks/193183.html</trackback:ping><description><![CDATA[     鎽樿: 褰?timeout = 0錛?鍗?Sleep(0)錛屽鏋滅嚎紼嬭皟搴﹀櫒鐨勫彲榪愯闃熷垪涓湁澶т簬鎴栫瓑浜庡綋鍓嶇嚎紼嬩紭鍏堢駭鐨勫氨緇嚎紼嬪瓨鍦紝鎿嶄綔緋葷粺浼氬皢褰撳墠綰跨▼浠庡鐞嗗櫒涓婄Щ闄わ紝璋冨害鍏朵粬浼樺厛綰ч珮鐨勫氨緇嚎紼嬭繍琛岋紱濡傛灉鍙繍琛岄槦鍒椾腑鐨勬病鏈夊氨緇嚎紼嬫垨鎵鏈夊氨緇嚎紼嬬殑浼樺厛綰у潎浣庝簬褰撳墠綰跨▼浼樺厛綰э紝閭d箞褰撳墠綰跨▼浼氱戶緇墽琛岋紝灝卞儚娌℃湁璋冪敤 Sleep(0)涓鏍楓?<br> <br>褰?timeout > 0 鏃訛紝濡傦細Sleep(1)錛屼細寮曞彂綰跨▼涓婁笅鏂囧垏鎹細璋冪敤綰跨▼浼氫粠綰跨▼璋冨害鍣ㄧ殑鍙繍琛岄槦鍒椾腑琚Щ闄や竴孌墊椂闂達紝榪欎釜鏃墮棿孌電害絳変簬 timeout 鎵鎸囧畾鐨勬椂闂撮暱搴︺備負浠涔堣綰︾瓑浜庡憿錛熸槸鍥犱負鐫$湢鏃墮棿鍗曚綅涓烘縐掞紝榪欎笌緋葷粺鐨勬椂闂寸簿搴︽湁鍏熾傞氬父鎯呭喌涓嬶紝緋葷粺鐨勬椂闂寸簿搴︿負 10 ms錛岄偅涔堟寚瀹氫換鎰忓皯浜?10 ms浣嗗ぇ浜?0 ms 鐨勭潯鐪犳椂闂達紝鍧囦細鍚戜笂姹傚間負 10 ms銆?nbsp; <a href='http://m.shnenglu.com/kesalin/archive/2012/10/11/Sleep.html'>闃呰鍏ㄦ枃</a><img src ="http://m.shnenglu.com/kesalin/aggbug/193183.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/kesalin/" target="_blank">緗楁湞杈?/a> 2012-10-11 20:04 <a href="http://m.shnenglu.com/kesalin/archive/2012/10/11/Sleep.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>鏁板鍑芥暟澶囦喚銆傘傘?/title><link>http://m.shnenglu.com/kesalin/archive/2010/06/04/math_function.html</link><dc:creator>緗楁湞杈?/dc:creator><author>緗楁湞杈?/author><pubDate>Fri, 04 Jun 2010 10:38:00 GMT</pubDate><guid>http://m.shnenglu.com/kesalin/archive/2010/06/04/math_function.html</guid><wfw:comment>http://m.shnenglu.com/kesalin/comments/117183.html</wfw:comment><comments>http://m.shnenglu.com/kesalin/archive/2010/06/04/math_function.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/kesalin/comments/commentRss/117183.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/kesalin/services/trackbacks/117183.html</trackback:ping><description><![CDATA[     鎽樿: 鏁板鍑芥暟澶囦喚銆傘傘?nbsp; <a href='http://m.shnenglu.com/kesalin/archive/2010/06/04/math_function.html'>闃呰鍏ㄦ枃</a><img src ="http://m.shnenglu.com/kesalin/aggbug/117183.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/kesalin/" target="_blank">緗楁湞杈?/a> 2010-06-04 18:38 <a href="http://m.shnenglu.com/kesalin/archive/2010/06/04/math_function.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>銆愯瘧銆慥C10涓殑C++0x鐗規?part 3 : 澹版槑涔嬬被鍨?http://m.shnenglu.com/kesalin/archive/2009/06/07/86960.html緗楁湞杈?/dc:creator>緗楁湞杈?/author>Sun, 07 Jun 2009 01:28:00 GMThttp://m.shnenglu.com/kesalin/archive/2009/06/07/86960.htmlhttp://m.shnenglu.com/kesalin/comments/86960.htmlhttp://m.shnenglu.com/kesalin/archive/2009/06/07/86960.html#Feedback4http://m.shnenglu.com/kesalin/comments/commentRss/86960.htmlhttp://m.shnenglu.com/kesalin/services/trackbacks/86960.htmlPart 1 錛氫粙緇嶄簡Lambdas錛?璧嬩簣鏂版剰涔夌殑auto錛屼互鍙?static_assert錛?
Part 2( 涓 , 浜?, 涓?)錛氫粙緇嶄簡鍙沖煎紩鐢紙Rvalue References錛夛紱
Part 3錛氫粙緇嶄簡琛ㄨ揪寮忕被鍨嬶紙decltype錛?

VC10涓殑C++0x鐗規?Part 1,2,3 璇戞枃鎵撳寘涓嬭澆錛坉oc 鍜?pdf 鏍煎紡錛夛細 鐐規涓嬭澆

鏈枃鏄疨art 3銆?nbsp; 闃呰鍏ㄦ枃

]]>
銆愯瘧銆慥C10涓殑C++0x鐗規?Part 2 錛?錛夛細鍙沖煎紩鐢?/title><link>http://m.shnenglu.com/kesalin/archive/2009/06/05/86851.html</link><dc:creator>緗楁湞杈?/dc:creator><author>緗楁湞杈?/author><pubDate>Fri, 05 Jun 2009 07:09:00 GMT</pubDate><guid>http://m.shnenglu.com/kesalin/archive/2009/06/05/86851.html</guid><wfw:comment>http://m.shnenglu.com/kesalin/comments/86851.html</wfw:comment><comments>http://m.shnenglu.com/kesalin/archive/2009/06/05/86851.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/kesalin/comments/commentRss/86851.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/kesalin/services/trackbacks/86851.html</trackback:ping><description><![CDATA[<p> </p> <p style="TEXT-ALIGN: center"><span style="FONT-WEIGHT: bold">銆愯瘧銆慥C10涓殑C++0x鐗規?Part 2 錛?錛夛細鍙沖煎紩鐢?/span> <br></p> <p style="TEXT-ALIGN: center">鏉ユ簮錛?a title=vcvlog target=_blank>vcblog</a> 浣滆咃細Stephan T. Lavavej 緲昏瘧錛?a title=椋橀鐧戒簯鐨凜++鍗氬 href="http://m.shnenglu.com/kesalin" target=_blank>椋橀鐧戒簯</a>   </p> <p style="TEXT-ALIGN: center">(杞澆鏃惰娉ㄦ槑浣滆呭拰鍑哄銆傛湭緇忚鍙紝璇峰嬁鐢ㄤ簬鍟嗕笟鐢ㄩ? <br></p> <p>綆浠?</p> <div id="hvzpftn" class=postText><style> <!-- /* Font Definitions */ @font-face {font-family:Wingdings; panose-1:5 0 0 0 0 0 0 0 0 0; mso-font-charset:2; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:0 268435456 0 0 -2147483648 0;} @font-face {font-family:"MS Mincho"; panose-1:2 2 6 9 4 2 5 8 3 4; mso-font-alt:"錛汲 鏄庢湞"; mso-font-charset:128; mso-generic-font-family:modern; mso-font-pitch:fixed; mso-font-signature:-1610612033 1757936891 16 0 131231 0;} @font-face {font-family:瀹嬩綋; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:Century; panose-1:2 4 6 4 5 5 5 2 3 4; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:647 0 0 0 159 0;} @font-face {font-family:"MS PGothic"; panose-1:2 11 6 0 7 2 5 8 2 4; mso-font-charset:128; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-1610612033 1757936891 16 0 131231 0;} @font-face {font-family:Verdana; panose-1:2 11 6 4 3 5 4 4 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:536871559 0 0 0 415 0;} @font-face {font-family:"\@MS PGothic"; panose-1:2 11 6 0 7 2 5 8 2 4; mso-font-charset:128; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-1610612033 1757936891 16 0 131231 0;} @font-face {font-family:"\@瀹嬩綋"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"\@MS Mincho"; panose-1:2 2 6 9 4 2 5 8 3 4; mso-font-charset:128; mso-generic-font-family:modern; mso-font-pitch:fixed; mso-font-signature:-1610612033 1757936891 16 0 131231 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:Century; mso-fareast-font-family:"MS Mincho"; mso-bidi-font-family:"Times New Roman"; mso-font-kerning:1.0pt; mso-fareast-language:JA;} h1 {mso-margin-top-alt:auto; margin-right:0cm; mso-margin-bottom-alt:auto; margin-left:0cm; mso-pagination:widow-orphan; mso-outline-level:1; font-size:24.0pt; font-family:"MS PGothic"; mso-bidi-font-family:"MS PGothic"; mso-fareast-language:JA;} p.MsoHeader, li.MsoHeader, div.MsoHeader {margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; tab-stops:center 212.6pt right 425.2pt; layout-grid-mode:char; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:Century; mso-fareast-font-family:"MS Mincho"; mso-bidi-font-family:"Times New Roman"; mso-font-kerning:1.0pt; mso-fareast-language:JA;} p.MsoFooter, li.MsoFooter, div.MsoFooter {margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; tab-stops:center 212.6pt right 425.2pt; layout-grid-mode:char; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:Century; mso-fareast-font-family:"MS Mincho"; mso-bidi-font-family:"Times New Roman"; mso-font-kerning:1.0pt; mso-fareast-language:JA;} a:link, span.MsoHyperlink {color:blue; text-decoration:underline; text-underline:single;} a:visited, span.MsoHyperlinkFollowed {color:purple; text-decoration:underline; text-underline:single;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:595.3pt 841.9pt; margin:99.25pt 3.0cm 3.0cm 3.0cm; mso-header-margin:42.55pt; mso-footer-margin:49.6pt; mso-paper-source:0; layout-grid:18.0pt;} div.Section1 {page:Section1;} --> </style> <p>榪欎竴緋誨垪鏂囩珷浠嬬粛Microsoft Visual Studio 2010 涓敮鎸佺殑C++ 0x鐗規э紝鐩墠鏈変笁閮ㄥ垎銆?<br><a title="VC10涓殑C++0x鐗規?part 1" target=_blank>Part 1</a> 錛氫粙緇嶄簡Lambdas錛?璧嬩簣鏂版剰涔夌殑auto錛屼互鍙?static_assert錛?<br>Part 2( <a title="VC10涓殑C++0x鐗規?part 2 絎竴閮ㄥ垎" href="http://m.shnenglu.com/kesalin/archive/2009/05/28/85983.html" target=_blank>涓</a> , <a title="VC10涓殑C++0x鐗規?part 2 絎簩閮ㄥ垎" href="http://m.shnenglu.com/kesalin/archive/2009/06/04/86720.html" target=_blank>浜?/a> , <a title="VC10涓殑C++0x鐗規?part 2 絎笁閮ㄥ垎 " href="http://m.shnenglu.com/kesalin/archive/2009/06/05/86851.html" target=_blank>涓?/a> )錛氫粙緇嶄簡鍙沖煎紩鐢紙Rvalue References錛夛紱 <br><a title="VC10涓殑C++0x鐗規?part 3" href="http://m.shnenglu.com/kesalin/archive/2009/06/07/86960.html" target=_blank>Part 3</a>錛氫粙緇嶄簡琛ㄨ揪寮忕被鍨嬶紙decltype錛?br><br>VC10涓殑C++0x鐗規?Part 1,2,3 璇戞枃鎵撳寘涓嬭澆錛坉oc 鍜?pdf 鏍煎紡錛夛細 <a title="VC10涓殑C++0x鐗規э紙Part 1,2,3錛夎瘧鏂嘾oc鍜宲df鏂囨。" href="http://m.shnenglu.com/Files/kesalin/Cplusplus0x_in_VC10.zip" target=_blank>鐐規涓嬭澆</a></p> </div> <br>鏈枃涓?Part 2 鐨勭涓夐〉 <p> </p> <p> <meta content=Word.Document name=ProgId> <meta content="Microsoft Word 11" name=Generator> <meta content="Microsoft Word 11" name=Originator> <object id=ieooui classid=clsid:38481807-ca0e-42d2-bf39-b33af135cc4d></object><style> st1\:*{behavior:url(#ieooui) } </style><style> <!-- /* Font Definitions */ @font-face {font-family:"錛汲 鏄庢湞"; panose-1:2 2 6 9 4 2 5 8 3 4; mso-font-alt:"MS Mincho"; mso-font-charset:128; mso-generic-font-family:roman; mso-font-pitch:fixed; mso-font-signature:-1610612033 1757936891 16 0 131231 0;} @font-face {font-family:SimSun; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:瀹嬩綋; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:Century; panose-1:2 4 6 4 5 5 5 2 3 4; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:647 0 0 0 159 0;} @font-face {font-family:"錛汲 錛般偞銈楓儍銈?; panose-1:2 11 6 0 7 2 5 8 2 4; mso-font-charset:128; mso-generic-font-family:modern; mso-font-pitch:variable; mso-font-signature:-1610612033 1757936891 16 0 131231 0;} @font-face {font-family:Verdana; panose-1:2 11 6 4 3 5 4 4 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:536871559 0 0 0 415 0;} @font-face {font-family:"\@錛汲 錛般偞銈楓儍銈?; panose-1:2 11 6 0 7 2 5 8 2 4; mso-font-charset:128; mso-generic-font-family:modern; mso-font-pitch:variable; mso-font-signature:-1610612033 1757936891 16 0 131231 0;} @font-face {font-family:"\@SimSun"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"\@錛汲 鏄庢湞"; panose-1:2 2 6 9 4 2 5 8 3 4; mso-font-charset:128; mso-generic-font-family:roman; mso-font-pitch:fixed; mso-font-signature:-1610612033 1757936891 16 0 131231 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0mm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:Century; mso-fareast-font-family:"錛汲 鏄庢湞"; mso-bidi-font-family:"Times New Roman"; mso-font-kerning:1.0pt;} h1 {mso-margin-top-alt:auto; margin-right:0mm; mso-margin-bottom-alt:auto; margin-left:0mm; mso-pagination:widow-orphan; mso-outline-level:1; font-size:24.0pt; font-family:"錛汲 錛般偞銈楓儍銈?; mso-bidi-font-family:"錛汲 錛般偞銈楓儍銈?; font-weight:bold;} p.MsoHeader, li.MsoHeader, div.MsoHeader {margin:0mm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; tab-stops:center 212.6pt right 425.2pt; layout-grid-mode:char; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:Century; mso-fareast-font-family:"錛汲 鏄庢湞"; mso-bidi-font-family:"Times New Roman"; mso-font-kerning:1.0pt;} p.MsoFooter, li.MsoFooter, div.MsoFooter {margin:0mm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; tab-stops:center 212.6pt right 425.2pt; layout-grid-mode:char; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:Century; mso-fareast-font-family:"錛汲 鏄庢湞"; mso-bidi-font-family:"Times New Roman"; mso-font-kerning:1.0pt;} a:link, span.MsoHyperlink {color:blue; text-decoration:underline; text-underline:single;} a:visited, span.MsoHyperlinkFollowed {color:purple; text-decoration:underline; text-underline:single;} p {mso-margin-top-alt:auto; margin-right:0mm; mso-margin-bottom-alt:auto; margin-left:0mm; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"錛汲 錛般偞銈楓儍銈?; mso-bidi-font-family:"錛汲 錛般偞銈楓儍銈?;} span.trans {mso-style-name:trans;} span.apple-style-span {mso-style-name:apple-style-span;} span.apple-converted-space {mso-style-name:apple-converted-space;} p.greentitle, li.greentitle, div.greentitle {mso-style-name:greentitle; mso-margin-top-alt:auto; margin-right:0mm; mso-margin-bottom-alt:auto; margin-left:0mm; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"錛汲 錛般偞銈楓儍銈?; mso-bidi-font-family:"錛汲 錛般偞銈楓儍銈?;} p.inner, li.inner, div.inner {mso-style-name:inner; mso-margin-top-alt:auto; margin-right:0mm; mso-margin-bottom-alt:auto; margin-left:0mm; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"錛汲 錛般偞銈楓儍銈?; mso-bidi-font-family:"錛汲 錛般偞銈楓儍銈?;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:612.0pt 792.0pt; margin:99.25pt 30.0mm 30.0mm 30.0mm; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} /* List Definitions */ @list l0 {mso-list-id:986742580; mso-list-type:hybrid; mso-list-template-ids:-1336744774 284093962 67698711 67698705 67698703 67698711 67698705 67698703 67698711 67698705;} @list l0:level1 {mso-level-text:%1錛? mso-level-tab-stop:18.0pt; mso-level-number-position:left; margin-left:18.0pt; text-indent:-18.0pt; mso-fareast-font-family:"錛汲 錛般偞銈楓儍銈?;} ol {margin-bottom:0mm;} ul {margin-bottom:0mm;} --> </style><strong>杞彂闂</strong><br><br>鍦ㄧ▼搴忓憳涓嶇敤鍐欓珮搴︽硾鍖栫殑浠g爜鐨勬椂鍊欙紝C++98/03 鐨?lvalue錛?rvalue錛?寮曠敤錛岃繕鏈夋ā鏉跨湅璧鋒潵鏄緢瀹岀編鐨勩傚亣璁句綘瑕佸啓涓涓畬鍏ㄦ硾鍖栫殑鍑芥暟 outer()錛岃繖涓嚱鏁扮殑鐩殑鏄皢浠繪剰鏁扮洰涓換鎰忕被鍨嬬殑鍙傛暟浼犻掞紙涔熷氨鏄?#8220;杞彂”錛夌粰鍑芥暟 inner()銆傚凡鏈夊緢澶氫笉閿欑殑瑙e喅鏂規錛屾瘮濡?factory 鍑芥暟 make_shared<T>(args) 鏄妸 args 浼犵粰 T 鐨勬瀯閫犲嚱鏁幫紝鐒跺悗榪斿洖 shared_ptr<T>銆傦紙榪欐牱灝辨妸 T 瀵硅薄鍜岀敤浜庡瀹冭繘琛屽紩鐢ㄨ鏁扮殑浠g爜瀛樺偍鍒板悓涓鍧楀姩鎬佸唴瀛樹腑錛屾ц兘涓婁笌渚靛叆寮忓紩鐢ㄨ鏁頒竴鏍峰ソ錛夛紱 鑰屽儚 function<Ret(args)> 榪欐牱鐨勫寘瑁呯被鏄妸鍙傛暟浼犵粰鍏跺唴閮ㄥ瓨鍌ㄧ殑鍑芥暟瀵硅薄錛坒unctor錛夛紝絳夌瓑銆傚湪榪欑瘒鏂囩珷閲岋紝鎴戜滑鍙 outer() 鏄浣曟妸鍙傛暟浼犻掔粰 inner() 榪欓儴鍒嗘劅鍏磋叮銆傝嚦浜?outer() 鐨勮繑鍥炵被鍨嬫槸鎬庝箞鍐沖畾鐨勬槸鍙﹀鐨勯棶棰橈紙鏈夋椂鍊欏緢綆鍗曪紝濡?make_shared<T>(args) 鎬繪槸榪斿洖 shared_prt<T>錛岋級錛屼絾瑕佸湪瀹屽叏鎼炲畾榪欎釜闂鐨勪竴鑸寲鎯呭喌錛屼綘灝辮鐢ㄥ埌 C++0x鐨?decltype 鐗規т簡錛夈?/p> <p> </p> <p>濡傛灉涓嶅甫鍙傛暟錛屽氨涓嶅瓨鍦ㄨ繖鏍風殑闂錛岄偅涔堝甫涓涓弬鏁版儏鍐靛憿錛熻鎴戜滑灝濊瘯鍐欎釜 outer錛堬級 錛?/p> <p> </p> <p><strong>template <typename T> void outer(T& t) {</strong></p> <p><strong>    inner(t);</strong></p> <p><strong>}</strong></p> <p> </p> <p>闂?棰樻潵浜嗭紝濡傛灉浼犵粰瀹冪殑鍙傛暟鏄潪甯擱噺 rvalue錛岄偅鎴戜滑灝辨棤娉曡皟鐢?outer()銆傚鏋?inner() 鎺ユ敹 const int& 鍨嬬殑鍙傛暟錛岄偅 inner(5) 鏄彲浠ラ氳繃緙栬瘧鐨勶紝浣嗘槸 outer(5) 灝辯紪璇戜笉榪囦簡銆傚洜涓?T 浼氳鎺ㄥ涓?int錛?鑰?int& 鏄笉鑳界粦瀹氬埌甯擱噺 5 鐨勩?/p> <p> </p> <p>濂藉惂錛岃鎴戜滑璇曡瘯榪欎釜錛?/p> <p> </p> <p><strong>template <typename T> void outer(const T& t) {</strong></p> <p><strong>    inner(t);</strong></p> <p><strong>}</strong></p> <p> </p> <p>濡傛灉 inner錛堬級鎺ユ敹 int& 鍨嬪弬鏁幫紝閭e氨浼氳繚娉?const 姝g‘鎬э紝緙栬瘧閮借繃涓嶄簡銆?/p> <p> </p> <p>鐜板湪錛屼綘鍙互閲嶈澆涓や釜鍒嗗埆甯?T& 鍜?const T& 鍙傛暟鐨?outer錛堬級錛岃繖紜疄綆$敤銆傚綋浣犺皟鐢?outer錛堬級鏃訛紝灝卞儚鐩存帴璋冪敤 inner錛堬級 涓鏍楓?/p> <p> </p> <p>鍙儨鐨勬槸錛岃繖涓柟娉曞湪澶氬弬鏁扮殑鎯呭喌涓嬪氨楹葷儲浜嗭紙璇戞敞錛氳鍐欑殑閲嶈澆鍑芥暟澶浜嗭級銆備綘灝卞緱涓烘瘡涓涓弬鏁板儚 T1& 鍜?const T1&, T2& 鍜?const T2& 絳夎繖鏍瘋繘琛岄噸杞斤紝瑕侀噸杞界殑鍑芥暟鏁扮洰鍛堟寚鏁扮駭澧為暱銆傦紙VC9 SP1 鐨?tr1錛氾細bind() 灝卞璁╀漢鎰熷埌緇濇湜浜嗭紝瀹冧負 5 涓弬鏁拌繖涔堥噸杞藉嚭浜?63 涓嚱鏁般傚鏋滀笉榪欎箞铔共鐨勮瘽錛屾病鏈夊儚榪欓噷鐨勯暱綃囩瘡榪幫紝鎴戜滑灝卞緢闅捐窡浣跨敤鑰呰В閲婁負浠涔堜笉鑳借皟鐢ㄧ敤 1729 榪欐牱鐨?ravlue 鍋氬弬鏁扮殑鍑芥暟銆備負浜嗕駭鐢熷嚭榪欎簺閲嶈澆鍑芥暟浣跨敤浜嗕護浜轟綔鍛曠殑棰勫鐞嗘満鍒訛紝鎭跺績鍒頒綘閮戒笉鎯崇煡閬撳畠錛夈?/p> <p> </p> <p>鍦?C++98/03 涓紝杞彂闂鏄緢涓ラ噸鐨勶紝鑰屼笖鏈川涓婃棤瑙o紙蹇呴』姹傚姪浜庢伓蹇冪殑棰勫鐞嗘満鍒訛紝榪欎細涓ラ噸鎷栨參緙栬瘧閫熷害錛岃繕璁╀唬鐮佸彉寰楅毦浠ラ槄璇伙級銆傛葷畻錛?rvalue 浼橀泤鍦拌В鍐充簡榪欎釜闂銆?/p> <p> </p> <p><strong>瀹岀編</strong><strong>杞彂</strong><strong>錛?/strong><strong> </strong><strong>妯″紡</strong></p> <p> </p> <p>瀹岀編杞彂璁╀綘鑳界畝鍗曡屾竻鏅板湴鍙啓涓涓ā鏉垮嚱鏁板氨鍙互杞彂鎵鏈夌殑鍙傛暟緇欎換鎰忓嚱鏁幫紝涓嶇瀹冨甫鍑犱釜鍙傛暟錛屼篃涓嶇鍙傛暟綾誨瀷鏄粈涔堛傝屼笖鍙傛暟鐨勯潪甯擱噺/甯擱噺錛?lvalue/rvalue 灞炴ч兘鑳藉緱浠ヤ繚鐣欙紝璁╀綘鍙互鍍忎嬌鐢?inner錛堬級 涓鏍蜂嬌鐢?outer錛堬級錛岃繕鍙互鍜?move 璇剰涓璧風敤浠庤岃幏寰楅澶栫殑濂藉銆傦紙 C++0x 鐨勫彉闀挎ā鏉挎妧鏈В鍐充簡“浠繪剰鏁扮洰”榪欓儴鍒嗭紝鎴戜滑鍦ㄨ繖閲屾妸 N 鐪嬪仛浠繪剰鏁扮洰錛夈備箥鐪嬩箣涓嬪緢紲炲錛屽疄闄呬笂寰堢畝鍗曪細</p> <p> </p> <p>C:\Temp>type perfect.cpp</p> <p>#include <iostream></p> <p>#include <ostream></p> <p>using namespace std;</p> <p> </p> <p>template <typename T> struct Identity {</p> <p>    typedef T type;</p> <p>};</p> <p> </p> <p>template <typename T> T&& Forward(typename Identity<T>::type&& t) {</p> <p>    return t;</p> <p>}</p> <p> </p> <p>void inner(int&, int&) {</p> <p>    cout << "inner(int&, int&)" << endl;</p> <p>}</p> <p> </p> <p>void inner(int&, const int&) {</p> <p>    cout << "inner(int&, const int&)" << endl;</p> <p>}</p> <p> </p> <p>void inner(const int&, int&) {</p> <p>    cout << "inner(const int&, int&)" << endl;</p> <p>}</p> <p> </p> <p>void inner(const int&, const int&) {</p> <p>    cout << "inner(const int&, const int&)" << endl;</p> <p>}</p> <p> </p> <p><strong>template <typename T1, typename T2> void outer(T1&& t1, T2&& t2) {</strong></p> <p><strong>    inner(Forward<T1>(t1), Forward<T2>(t2));</strong></p> <p><strong>}</strong></p> <p> </p> <p>int main() {</p> <p>    int a = 1;</p> <p>    const int b = 2;</p> <p> </p> <p>    cout << "Directly calling inner()." << endl;</p> <p> </p> <p>    inner(a, a);</p> <p>    inner(b, b);</p> <p>    inner(3, 3);</p> <p> </p> <p>    inner(a, b);</p> <p>    inner(b, a);</p> <p> </p> <p>    inner(a, 3);</p> <p>    inner(3, a);</p> <p> </p> <p>    inner(b, 3);</p> <p>    inner(3, b);</p> <p> </p> <p>    cout << endl << "Calling outer()." << endl;</p> <p> </p> <p>    outer(a, a);</p> <p>    outer(b, b);</p> <p>    outer(3, 3);</p> <p> </p> <p>    outer(a, b);</p> <p>    outer(b, a);</p> <p> </p> <p>    outer(a, 3);</p> <p>    outer(3, a);</p> <p> </p> <p>    outer(b, 3);</p> <p>    outer(3, b);</p> <p>}</p> <p> </p> <p>C:\Temp>cl /EHsc /nologo /W4 perfect.cpp</p> <p>perfect.cpp</p> <p> </p> <p>C:\Temp>perfect</p> <p>Directly calling inner().</p> <p>inner(int&, int&)</p> <p>inner(const int&, const int&)</p> <p>inner(const int&, const int&)</p> <p>inner(int&, const int&)</p> <p>inner(const int&, int&)</p> <p>inner(int&, const int&)</p> <p>inner(const int&, int&)</p> <p>inner(const int&, const int&)</p> <p>inner(const int&, const int&)</p> <p> </p> <p>Calling outer().</p> <p>inner(int&, int&)</p> <p>inner(const int&, const int&)</p> <p>inner(const int&, const int&)</p> <p>inner(int&, const int&)</p> <p>inner(const int&, int&)</p> <p>inner(int&, const int&)</p> <p>inner(const int&, int&)</p> <p>inner(const int&, const int&)</p> <p>inner(const int&, const int&)</p> <p> </p> <p>涓よ錛佸畬緹庤漿鍙戝彧鐢ㄤ簡涓よ錛佸綆媧佸惂錛?/p> <p> </p> <p>榪欎釜渚嬪瓙紺鴻寖浜嗘庝箞鎶?t1 鍜?t2 浠?outer錛堬級 閫忔槑鍦拌漿鍙戠粰 inner錛堬級錛?inner錛堬級 鍙互鐭ラ亾瀹冧滑鐨勯潪甯擱噺/甯擱噺錛?lvalue/ravlue 灞炴э紝灝卞儚inner鏄鐩存帴璋冪敤鐨勯偅鏍楓?/p> <p> </p> <p>璺?std錛氾細move() 涓鏍鳳紝 std::identify 鍜?std::forward() 閮芥槸鍦?C++<utility> 涓畾涔夌殑錛?VC10 浼氭湁錛?VC10 CTP涓病鏈夛級銆傛垜灝嗘紨紺烘庝箞鏉ュ疄鐜板畠浠傦紙鍐嶆錛屾垜灝嗕氦鏇夸嬌鐢?std::identity 鍜屾垜鐨?Identity錛?std::forward() 鍜屾垜鐨?Forward()錛屽洜涓轟粬浠殑瀹炵幇鏄瓑浠風殑銆傦級</p> <p> </p> <p>鐜板湪錛岃鎴戜滑鏉ユ彮寮“欖旀湳“鐨勭縐橀潰綰憋紝鍏跺疄瀹冮潬鐨勫氨鏄ā鏉垮弬鏁版帹瀵煎拰寮曠敤鎶樺彔(reference collapsing)鎶鏈?/p> <p><strong> </strong></p> <p><strong>rvalue </strong><strong>寮曠敤錛氭ā鏉垮弬鏁版帹</strong><strong>瀵?/strong><strong>鍜屽紩鐢ㄦ姌鍙?reference collapsing)</strong><strong></strong></p> <p> </p> <p>rvalue 寮曠敤涓庢ā鏉夸互涓縐嶇壒鍒殑鏂瑰紡鐩鎬簰浣滅敤銆備笅闈㈡槸涓涓ず渚嬶細</p> <p> </p> <p>C:\Temp>type collapse.cpp</p> <p>#include <iostream></p> <p>#include <ostream></p> <p>#include <string></p> <p>using namespace std;</p> <p> </p> <p>template <typename T> struct Name;</p> <p> </p> <p>template <> struct Name<string> {</p> <p>    static const char * get() {</p> <p>        return "string";</p> <p>    }</p> <p>};</p> <p> </p> <p>template <> struct Name<const string> {</p> <p>    static const char * get() {</p> <p>        return "const string";</p> <p>    }</p> <p>};</p> <p> </p> <p>template <> struct Name<string&> {</p> <p>    static const char * get() {</p> <p>        return "string&";</p> <p>    }</p> <p>};</p> <p> </p> <p>template <> struct Name<const string&> {</p> <p>    static const char * get() {</p> <p>        return "const string&";</p> <p>    }</p> <p>};</p> <p> </p> <p>template <> struct Name<string&&> {</p> <p>    static const char * get() {</p> <p>        return "string&&";</p> <p>    }</p> <p>};</p> <p> </p> <p>template <> struct Name<const string&&> {</p> <p>    static const char * get() {</p> <p>        return "const string&&";</p> <p>    }</p> <p>};</p> <p> </p> <p>template <typename T> void quark(T&& t) {</p> <p>    cout << "t: " << t << endl;</p> <p>    cout << "T: " << Name<T>::get() << endl;</p> <p>    cout << "T&&: " << Name<T&&>::get() << endl;</p> <p>    cout << endl;</p> <p>}</p> <p> </p> <p>string strange() {</p> <p>    return "strange()";</p> <p>}</p> <p> </p> <p>const string charm() {</p> <p>    return "charm()";</p> <p>}</p> <p> </p> <p>int main() {</p> <p>    string up("up");</p> <p>    const string down("down");</p> <p> </p> <p>    quark(up);</p> <p>    quark(down);</p> <p>    quark(strange());</p> <p>    quark(charm());</p> <p>}</p> <p> </p> <p>C:\Temp>cl /EHsc /nologo /W4 collapse.cpp</p> <p>collapse.cpp</p> <p> </p> <p>C:\Temp>collapse</p> <p>t: up</p> <p>T: string&</p> <p>T&&: string&</p> <p> </p> <p>t: down</p> <p>T: const string&</p> <p>T&&: const string&</p> <p> </p> <p>t: strange()</p> <p>T: string</p> <p>T&&: string&&</p> <p> </p> <p>t: charm()</p> <p>T: const string</p> <p>T&&: const string&&</p> <p> </p> <p>榪欓噷钘夌敱 Name 鐨勬樉寮忚鏍艱鏄庢潵鎵撳嵃鍑虹被鍨嬨?/p> <p> </p> <p>褰撴垜浠皟鐢?quark(up) 鏃訛紝浼氳繘琛屾ā鏉垮弬鏁版帹瀵箋?quark() 鏄竴涓甫鏈夋ā鏉垮弬鏁?T 鐨勬ā鏉垮嚱鏁幫紝浣嗘槸鎴戜滑榪樻病鏈変負瀹冩彁渚涙樉寮忕殑綾誨瀷鍙傛暟錛堟瘮濡傚儚 quark<X>(up)榪欐牱鐨勶級銆傞氳繃姣旇緝鍑芥暟褰㈠弬綾誨瀷 Type&& 鍜屽嚱鏁板疄鍙傜被鍨嬶紙涓涓?string 綾誨瀷鐨?lvalue錛夋垜浠氨鑳芥帹瀵煎嚭妯℃澘瀹炲弬綾誨瀷銆傦紙璇戞敞錛氬師鏂囩敤 argument 琛ㄧず瀹炲弬錛宲arameter 琛ㄧず褰㈠弬錛?/p> <p> </p> <p>C++0x 浼氳漿鎹㈠嚱鏁板疄鍙傜殑綾誨瀷鍜屽艦鍙傜殑綾誨瀷錛岀劧鍚庡啀榪涜鍖歸厤銆?/p> <p> </p> <p>棣栧厛錛岃漿鎹㈠嚱鏁板疄鍙傜殑綾誨瀷銆傝繖閬靛驚涓鏉?strong>鐗規畩</strong><strong>瑙勫垯</strong>(鎻愭N2798 </p> <p> </p> <p>鐒跺悗錛岃漿鎹㈠嚱鏁板艦鍙傜殑綾誨瀷銆備笉綆℃槸 C++98/03 榪樻槸 C++0x 閮戒細瑙i櫎寮曠敤( lvalue 寮曠敤鍜?rvalue 寮曠敤鍦?C++0x 涓兘浼氳瑙i櫎鎺?銆傚湪鍓嶉潰渚嬪瓙鐨勫洓縐嶆儏褰腑錛岃繖鏍鋒垜浠細鎶?<strong>T&&</strong> 杞崲鎴?<strong>T</strong> 銆?/p> <p> </p> <p>浜庢槸錛?<strong>T</strong> <strong>浼氳鎺?/strong><strong>瀵?/strong><strong>鎴愬嚱鏁?/strong><strong>瀹?/strong><strong>鍙?/strong><strong>杞崲</strong><strong>涔嬪悗鐨?/strong><strong>綾?/strong><strong>鍨?/strong>銆?strong>up</strong> 鍜?<strong>down</strong> 閮芥槸 lvalue錛屽畠浠伒寰偅鏉$壒孌婅鍒欙紝榪欏氨鏄負浠涔?<strong>quark(up)  </strong>鎵撳嵃鍑?<strong>T:string&</strong>" 錛岃?<strong>quark(down)</strong> 鎵撳嵃鍑?"<strong>T: cosnt string&</strong>"鐨勫師鍥犮?strong>strange()</strong> 鍜?<strong>charm()</strong> 閮芥槸鍙沖鹼紝瀹冧滑閬靛驚涓鑸鍒欙紝榪欏氨鏄負浠涔?<strong>quark(strange())</strong> 鎵撳嵃鍑?"<strong>T: string</strong>" 鑰?<strong>quark(charm())</strong> 鎵撳嵃鍑?<strong>T: const string</strong>" 鐨勫師鍥犮?/p> <p> </p> <p>鏇挎崲鎿嶄綔浼氬湪綾誨瀷鎺ㄥ涔嬪悗榪涜銆傛ā鏉垮艦鍙?<strong>T</strong> 鍑虹幇鐨勬瘡涓涓湴鏂歸兘浼氳鏇挎崲鎴愭帹瀵煎嚭鏉ョ殑妯℃澘瀹炲弬綾誨瀷銆傚湪 <strong>quark(string())</strong> 涓?<strong>T</strong> 鏄?<strong>string </strong>錛屽洜姝?<strong>T&&</strong> 浼氭槸 <strong>string&&</strong> 銆傚悓鏍鳳紝鍦?<strong>quark(charm())</strong> 涓紝<strong>T</strong> 鏄?<strong>const string</strong> 錛?鍥犳 <strong>T&&</strong> 鏄?<strong>const string&&</strong> 銆備絾 quark(up) 鍜?quark(down) 涓嶅悓錛屽畠浠伒寰彟澶栫殑鐗規畩瑙勫垯銆?/p> <p> </p> <p>鍦?<strong>quark(up)</strong> 涓紝 <strong>T</strong> 鏄?<strong>string&</strong> 銆傝繘琛屾浛鎹㈢殑璇?<strong>T&&</strong> 灝辨垚浜?<strong>string& &&</strong> 錛屽湪 C++0x 涓細鎶樺彔錛坈ollapse錛夊紩鐢ㄧ殑寮曠敤錛?strong>寮曠敤鎶樺彔鐨?/strong><strong>瑙勫垯</strong><strong>灝辨槸</strong><strong>“lvalue </strong><strong>寮曠敤鏄?/strong><strong>浼?/strong><strong>鏌撴х殑</strong><strong>”</strong>銆?<strong>X& &</strong>, <strong>X& &&</strong> 鍜?<strong>X&& &</strong> 閮戒細琚姌鍙犳垚 <strong>X&</strong> 錛屽彧鏈?<strong>X&& &&</strong> 浼氳鎶樺彔鎴?<strong>X&&</strong> 銆傚洜姝?<strong>string& &&</strong> 琚姌鍙犳垚 <strong>string&</strong> 銆傚湪妯℃澘涓栫晫閲岋紝閭d簺鐪嬭搗鏉ュ儚 rvalue 寮曠敤鐨勪笢瑗垮茍涓嶄竴瀹氱湡鐨勫氨鏄?鍥犺?<strong>quark(up)</strong> 琚疄渚嬪寲涓?<strong>quark<string&>()</strong> 錛岃繘鑰?<strong>T&&</strong> 緇忔浛鎹笌鎶樺彔涔嬪悗鍙樻垚 <strong>string&</strong> 銆傛垜浠彲浠ヨ皟鐢?<strong>Name<T&&>::get()</strong> 鏉ラ獙璇佽繖涓?鍚屾牱錛?<strong>quark(down)</strong> 琚疄渚嬪寲涓?<strong>quark<const string&>()</strong> 錛岃繘鑰?<strong>T&&</strong> 緇忔浛鎹笌鎶樺彔涔嬪悗鍙樻垚 <strong>const string&</strong> 銆傚湪 C++98/03涓紝浣犲彲鑳戒範鎯簡甯擱噺鎬?constness)闅愯棌浜庢ā鏉垮艦鍙備腑(涔熷氨鏄鍙互浼?<strong>const Foo</strong> 瀵硅薄浣滃疄鍙傛潵璋冪敤褰㈠弬涓?<strong>T&</strong> 鐨勬ā鏉垮嚱鏁幫紝灝卞儚 <strong>T&</strong> 浼氭槸 <strong>const Foo&</strong> 涓鏍?錛屽湪 C++0x 涓紝宸﹀煎睘鎬?lvalueness) 涔熻兘闅愯棌浜庢ā鏉垮艦鍙備腑銆?/p> <p> </p> <p>閭eソ錛岃繖涓ゆ潯鐗規畩瑙勫垯瀵規垜浠湁浠涔堝獎鍝嶏紵鍦?quark() 鍐呴儴錛岀被鍨?<strong>T&&</strong> 鏈夌潃鍜屼紶緇?<strong>quark() </strong>鐨勫疄鍙備竴鏍風殑宸?鍙沖煎睘鎬?lvalueness/rvalueness)鍜屽父閲忔с傝繖鏍?<strong>rvalue 寮曠敤灝辮兘淇濇寔浣忓乏鍙?/strong><strong>鍊?/strong><strong>灞炴у拰甯擱噺鎬э紝鍋氬埌瀹岀編</strong><strong>杞彂</strong><strong>銆?/strong></p> <p><strong> </strong></p> <p><strong>瀹岀編</strong><strong>杞彂</strong><strong>錛?std::forward() 鍜?std::identidy 鏄?/strong><strong>鏍?/strong><strong>宸ヤ綔鐨?/strong></p> <p> </p> <p>璁╂垜浠啀鏉ョ湅鐪?outer() :</p> <p> </p> <p><strong>template <typename T1, typename T2> void outer(T1&& t1, T2&& t2) {</strong></p> <p><strong>    inner(Forward<T1>(t1), Forward<T2>(t2));</strong></p> <p><strong>}</strong></p> <p> </p> <p>鐜板湪鎴戜滑鏄庣櫧浜嗕負浠涔?strong> outer()</strong> 鐨勫艦鍙傛槸 <strong>T1&&</strong> 鍜?<strong>T2&&</strong> 綾誨瀷鐨勪簡錛屽洜涓哄畠浠兘澶熶繚鎸佷綇浼犵粰 <strong>outer()</strong> 鐨勫疄鍙傜殑淇℃伅銆傞偅涓轟粈涔堣繖閲岃璋冪敤 <strong>Forward<T1>()</strong> 鍜?<strong>Forward<T2>()</strong> 鍛紵榪樿寰椾箞錛屽叿鍚?lvalue 寮曠敤鍜屽叿鍚?rvalue 寮曠敤閮芥槸 lvalue 銆傚鏋?<strong>outer()</strong> 璋冪敤 <strong>inner(t1, t2)</strong> 錛岄偅涔?<strong>inner()</strong> 鎬繪槸浼氬綋 lvalue 鏉ュ紩鐢?<strong>t1</strong> 鍜?<strong>t2</strong> 錛岃繖灝辯牬鍧忎簡瀹岀編杞彂銆?/p> <p> </p> <p>騫?榪愮殑鏄紝涓嶅叿鍚?lvalue 寮曠敤鏄?lvalue錛屼笉鍏峰悕 rvalue 寮曠敤榪樻槸 rvalue 銆傚洜姝わ紝涓轟簡灝?t1 鍜?t2 杞彂緇?inner()錛屾垜浠渶瑕佸皢瀹冧滑浼犲埌涓涓府鍔╁嚱鏁頒腑鍘伙紝榪欎釜甯姪鍑芥暟縐婚櫎瀹冧滑鐨勫悕瀛楋紝淇濇寔浣忓畠浠殑灞炴т俊鎭傝繖灝辨槸 std::forward() 鍋氱殑浜嬫儏錛?/p> <p> </p> <p><strong>template <typename T> struct Identity {</strong></p> <p><strong>    typedef T type;</strong></p> <p><strong>};</strong></p> <p><strong> </strong></p> <p><strong>template <typename T> T&& Forward(typename Identity<T>::type&& t) {</strong></p> <p><strong>    return t;</strong></p> <p><strong>}</strong></p> <p> </p> <p>褰撴垜浠皟鐢?<strong>Forward<T1>(t1)</strong> 錛?<strong>Identidy</strong> 騫舵病鏈変慨鏀?<strong>T1</strong> 錛堝緢蹇垜浠鍒?<strong>Identidy</strong> 瀵?<strong>T1</strong> 鍋氫簡浠涔堬級銆傚洜姝?<strong>Forward<T1>()</strong> 鎺ユ敹 <strong>T1&&</strong> 錛岃繑鍥?<strong>T1&&</strong> 銆傝繖鏍峰氨縐婚櫎浜?<strong>t1</strong> 鐨勫悕瀛楋紝淇濇寔浣?<strong>t1</strong> 鐨勭被鍨嬩俊鎭紙鑰屼笉璁?<strong>t1</strong> 鏄粈涔堢被鍨嬶紝 string& 涔熷ソ, const string& 涔熷ソ, string&& 涔熷ソ鎴?const string&& 涔熷ソ錛夈傝繖鏍?<strong>inner()</strong> 鐪嬪埌鐨?<strong>Forward<T1>(t1)</strong> 錛屼笌 <strong>outer()</strong> 鎺ユ敹鐨勭涓涓疄鍙傛湁鐫鐩稿悓鐨勪俊鎭紝鍖呮嫭綾誨瀷錛宭valueness/rvalueness錛屽父閲忔х瓑絳夈傚畬緹庤漿鍙戝氨鏄繖鏍峰伐浣滅殑銆?/p> <p> </p> <p>浣犲彲鑳戒細濂藉濡傛灉涓嶅皬蹇冨啓鎴?<strong>Forward<T1&&>(t1) </strong>鍙堜細鎬庢牱鍛紵錛堣繖涓敊璇繕鏄洰璇變漢鐨勶紝鍥犱負 <strong>outer() </strong>鎺ユ敹鐨勫氨鏄?<strong>T1&& t1</strong> 錛夈傚緢騫歌繍錛屾病浠涔堝潖浜嬫儏浼氬彂鐢熴?<strong>Forward<T1&&>()</strong> 鎺ユ敹涓庤繑鍥炵殑閮芥槸 <strong>T1&& &&</strong> 錛岃繖浼氳鎶樺彔鎴?<strong>T1&&</strong> 銆備簬鏄紝<strong>Forward<T1>(t1)</strong> 鍜?<strong>Forward<T1&&>(t1)</strong> 鏄瓑浠風殑錛屾垜浠洿鍋忓ソ鍓嶈咃紝鏄洜涓哄畠瑕佺煭浜涖?/p> <p> </p> <p><strong>Identidy</strong> 鏄仛浠涔堢敤鐨勫憿錛熶負浠涔堜笅闈㈢殑浠g爜涓嶈兘宸ヤ綔錛?/p> <p> </p> <p><strong>template <typename T> T&& Forward(T&& t) { // BROKEN</strong></p> <p><strong>    return t;</strong></p> <p><strong>}</strong></p> <p> </p> <p>濡傛灉 <strong>Forward()</strong> 鍍忔槸涓婇潰閭f牱錛屽畠灝辮兘琚殣寮忚皟鐢紙涓嶅甫鏄庣‘鐨勬ā鏉垮弬鏁幫級銆傚綋鎴戜滑浼犵粰<strong> Forward()</strong> 涓涓?lvalue 瀹炲弬鏃訛紝妯℃澘鍙傛暟鎺ㄥ灝變粙鍏ヤ簡錛屽鎴戜滑鍓嶉潰鐪嬪埌鐨勯偅鏍蜂細灝?<strong>T&&</strong> 鍙樻垚 <strong>T&</strong>錛屼篃灝辨槸鍙樻垚涓涓?lvalue 寮曠敤銆傞棶棰樻潵浜嗭紝鍗充嬌褰㈠弬 <strong>T1&&</strong> 鍜?<strong>T2&&</strong> 鎸囨槑鏄?rvalue 寮曠敤錛屼絾鍦?<strong>outer()</strong> 涓紝鍏峰悕鐨?<strong>t1</strong> 鍜?<strong>t2</strong> 鍗存槸 lvaue 錛岃繖涓棶棰樻槸鎴戜滑涓鐩存兂瑕佽В鍐崇殑錛佷嬌鐢ㄤ笂闈㈤偅涓敊璇殑瀹炵幇錛?<strong>Forward<T1>(t1)</strong> 鏄彲浠ュ伐浣滅殑錛岃?<strong>Foarward(t1)</strong> 铏界劧鑳介氳繃緙栬瘧錛堝緢璇變漢鍝︼級浣嗕細鍑洪敊錛屽氨濡傚畠灝辨槸 <strong>t1</strong> 涓鏍楓傜湡鏄棝鑻︾殑婧愭硥鍟婏紝鍥犳錛?strong>Identity</strong> <strong>琚敤鏉ラ樆姝㈡ā鏉垮弬鏁版帹</strong><strong>瀵?/strong>銆?strong>typename Identity<T>::type</strong> 涓殑閭e鍐掑彿灝卞儚緇濈紭浣擄紝妯℃澘鍙傛暟鎺ㄥ鏃犳硶絀胯秺瀹冿紝鏈夋ā鏉跨紪紼嬬粡楠岀殑紼嬪簭鍛樺簲璇ュ姝ゅ緢鐔熸倝浜嗭紝鍥犱負榪欏湪 C++98/03 鍜?C++0x 涓槸涓鏍風殑銆傦紙瑕佽В閲婅繖涓槸鍙﹀鐨勪簨鎯呬簡錛?/p> <p> </p> <p><strong>move </strong><strong>璇?/strong><strong>鎰忥細</strong><strong> std::move() </strong><strong>鏄?/strong><strong>鏍?/strong><strong>宸ヤ綔鐨?/strong></p> <p> </p> <p>鐜板湪鎴戜滑宸茬粡瀛︿範浜嗘ā鏉垮弬鏁版帹瀵煎拰寮曠敤鎶樺彔鐨勭壒孌婅鍒欙紝璁╂垜浠啀鏉ョ湅鐪?std::move() :</p> <p> </p> <p><strong>template <typename T> struct RemoveReference {</strong></p> <p><strong>     typedef T type;</strong></p> <p><strong>};</strong></p> <p><strong> </strong></p> <p><strong>template <typename T> struct RemoveReference<T&> {</strong></p> <p><strong>     typedef T type;</strong></p> <p><strong>};</strong></p> <p><strong> </strong></p> <p><strong>template <typename T> struct RemoveReference<T&&> {</strong></p> <p><strong>     typedef T type;</strong></p> <p><strong>};</strong></p> <p><strong> </strong></p> <p><strong>template <typename T> typename RemoveReference<T>::type&& Move(T&& t) {</strong></p> <p><strong>    return t;</strong></p> <p><strong>}</strong></p> <p><strong> </strong></p> <p><strong>RemoveReference </strong>鏈哄埗鍩烘湰涓婃槸澶嶅埗 C++0x <type_traits> 涓殑 <strong>std::remove_reference</strong> 銆備婦渚嬫潵璇達紝<strong>RemoveReference<string>::type</strong> , <strong>RemoveReference<string&>::type</strong> 鍜?<strong>RemoveReference<string&&>::type</strong> 閮芥槸 <strong>string </strong>銆?/p> <p> </p> <p>鍚屾牱錛?<strong>move()</strong> 鏈哄埗涔熷熀鏈笂鏄鍒?C++0x <utility> 涓殑 <strong>std::move()</strong>銆?</p> <p>· 褰撹皟鐢?<strong>Move(string)</strong>, <strong>string </strong>鏄竴涓?lvalue 鏃訛紝 <strong>T</strong> 浼氳鎺ㄥ涓?<strong>string&</strong> 錛屼簬鏄?strong> Move()</strong> 鎺ユ敹鐨勫氨鏄?<strong>string&</strong> (緇忔姌鍙犱箣鍚?騫惰繑鍥?<strong>string&&</strong> (緇?<strong>RemoveReference </strong>涔嬪悗)銆?/p> <p> </p> <p>· 褰撹皟鐢?<strong>Move(const string)</strong>, <strong>const</strong> <strong>string </strong>鏄竴涓?lvalue 鏃訛紝 <strong>T</strong> 浼氳鎺ㄥ涓?<strong>const string&</strong> 錛屼簬鏄?<strong>Move()</strong> 鎺ユ敹鐨勫氨鏄?<strong>const string&&</strong> (緇忔姌鍙犱箣鍚?騫惰繑鍥?<strong>const string&&</strong> (緇?<strong>RemoveReference </strong>涔嬪悗)銆?/p> <p> </p> <p>· 褰撹皟鐢?<strong>Move(string)</strong>, <strong>string </strong>鏄竴涓?rvalue 鏃訛紝 <strong>T</strong> 浼氳鎺ㄥ涓?<strong>string</strong> 錛屼簬鏄?strong> Move()</strong> 鎺ユ敹鐨勫氨鏄?<strong>string&&</strong> 騫惰繑鍥?<strong>string&&</strong> 銆?/p> <p> </p> <p>· 褰撹皟鐢?<strong>Move(const string)</strong>, <strong>const</strong> <strong>string </strong>鏄竴涓?rvalue 鏃訛紝 <strong>T</strong> 浼氳鎺ㄥ涓?<strong>const string</strong> 錛屼簬鏄?<strong>Move()</strong> 鎺ユ敹鐨勫氨鏄?<strong>const string&&</strong> 騫惰繑鍥?<strong>const string&&</strong> 銆?/p> <p> </p> <p>榪欏氨鏄?Move() 濡備綍淇濇寔鍏跺弬鏁扮殑綾誨瀷鍜屽父閲忔э紝榪樿兘鎶?lvalue 杞崲鎴?rvalue 鐨勮繃紼嬨?/p> <p> </p> <p><strong>鍥?/strong><strong>欏?/strong><strong></strong></p> <p>濡傛灉浣犳兂瀵?rvalue 寮曠敤鏈夋洿澶氫簡 瑙o紝浣犲彲浠ュ幓璇繪湁鍏沖畠浠殑鎻愭銆傝娉ㄦ剰錛屾彁妗堜笌鐜板湪鐨勫喅瀹氬彲鑳藉凡緇忎笉鍚屼簡錛?rvalue 寮曠敤宸茬粡琚暣鍚堝埌 C++0x 鑽夋涓潵浜嗭紝鍦ㄩ偅閲屽畠寰楀埌鎸佺畫鐨勬敼榪涖傛湁浜涙彁妗堟垨宸蹭笉鍐嶆紜紝鎴栧凡榪囨椂錛屾垨宸叉湁浜嗘浛浠f柟妗堬紝灝辨病鏈夎閲囩撼銆傛棤璁烘庢牱錛屽畠浠繕鏄兘鎻愪緵涓浜涙湁鐢ㄤ俊鎭殑銆?/p> <p> </p> <p><a >N1377</a>, <a >N1385</a>, 鍜?<a >N1690</a> 鏄富瑕佺殑鎻愭錛?a >N2118</a> 鍖呭惈琚暣鍚堣繘鏍囧噯鑽夋涔嬪墠鐨勬渶鍚庣増鏈?<a >N1784</a>, <a >N1821</a>, <a >N2377</a>, 鍜?<a >N2439</a> 璁板綍浜?#8220;灝?Move 璇剰鎵╁睍鍒?*this ”鐨勬紨鍖栬繃紼嬶紝榪欎釜涔熻鏁村悎鍒?C++0x 涓潵浜嗭紝浣嗚繕娌℃湁鍦╒C10 涓緱鍒板疄鐜般?/p> <p> </p> <p><strong>灞曟湜</strong></p> <p><a >N2812</a> “Rvalue 寮曠敤鐨勫畨鍏ㄩ棶棰橈紙浠ュ強濡備綍瑙e喅錛?#8221; 鎻愬嚭浜嗗鍒濆鍖栬鍒欑殑淇敼錛屽畠紱佹 rvalue 寮曠敤緇戝畾鍒?lvalue 銆?榪欎笉浼氬獎鍝?move 璇剰鍜屽畬緹庤漿鍙戯紝鎵浠ュ畠涓嶄細璁╀綘鍒氬鍒扮殑鏂版妧鏈け鏁堬紙瀹冨彧鏄慨鏀逛簡 std::move() 鍜?std::forward() 鐨勫疄鐜幫級銆?/p> <p> </p> <p>Stephan T. Lavavej</p> <p>Visual C++ Libraries Developer</p> <p>Published Tuesday, February 03, 2009 9:27 AM by <a >vcblog</a></p> <p>緲昏瘧錛?a href="http://m.shnenglu.com/kesalin/">椋橀鐧戒簯</a></p> <p> </p> <p style="TEXT-ALIGN: center">(杞澆鏃惰娉ㄦ槑浣滆呭拰鍑哄銆傛湭緇忚鍙紝璇峰嬁鐢ㄤ簬鍟嗕笟鐢ㄩ?</p> <p style="TEXT-ALIGN: center"> < <a href="http://m.shnenglu.com/kesalin/archive/2009/06/01/86461.html">絎竴欏?/a>錛?<a href="http://m.shnenglu.com/kesalin/archive/2009/06/04/86720.html">絎簩欏?/a>錛?鏈〉></p> <br> <p> </p> <br><br> <img src ="http://m.shnenglu.com/kesalin/aggbug/86851.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/kesalin/" target="_blank">緗楁湞杈?/a> 2009-06-05 15:09 <a href="http://m.shnenglu.com/kesalin/archive/2009/06/05/86851.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>銆愯瘧銆慥C10涓殑C++0x鐗規?part 2錛?錛?鍙沖煎紩鐢?/title><link>http://m.shnenglu.com/kesalin/archive/2009/06/04/86720.html</link><dc:creator>緗楁湞杈?/dc:creator><author>緗楁湞杈?/author><pubDate>Thu, 04 Jun 2009 01:37:00 GMT</pubDate><guid>http://m.shnenglu.com/kesalin/archive/2009/06/04/86720.html</guid><wfw:comment>http://m.shnenglu.com/kesalin/comments/86720.html</wfw:comment><comments>http://m.shnenglu.com/kesalin/archive/2009/06/04/86720.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://m.shnenglu.com/kesalin/comments/commentRss/86720.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/kesalin/services/trackbacks/86720.html</trackback:ping><description><![CDATA[<p style="TEXT-ALIGN: center"> <h3 style="FONT-FAMILY: 瀹嬩綋; TEXT-ALIGN: center">銆愯瘧銆慥C10涓殑C++0x鐗規?part 2錛?錛?鍙沖煎紩鐢?/h3> 鏉ユ簮錛?a title=vcvlog target=_blank>vcblog</a> 浣滆咃細Stephan T. Lavavej 緲昏瘧錛?a title=椋橀鐧戒簯鐨凜++鍗氬 href="http://m.shnenglu.com/kesalin" target=_blank>椋橀鐧戒簯</a>   <p> </p> <p style="FONT-SIZE: 12pt"></p> <p style="TEXT-ALIGN: center">(杞澆鏃惰娉ㄦ槑浣滆呭拰鍑哄銆傛湭緇忚鍙紝璇峰嬁鐢ㄤ簬鍟嗕笟鐢ㄩ? <br></p> <p>綆浠?</p> <div id="hvzpftn" class=postText><style> <!-- /* Font Definitions */ @font-face {font-family:Wingdings; panose-1:5 0 0 0 0 0 0 0 0 0; mso-font-charset:2; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:0 268435456 0 0 -2147483648 0;} @font-face {font-family:"MS Mincho"; panose-1:2 2 6 9 4 2 5 8 3 4; mso-font-alt:"錛汲 鏄庢湞"; mso-font-charset:128; mso-generic-font-family:modern; mso-font-pitch:fixed; mso-font-signature:-1610612033 1757936891 16 0 131231 0;} @font-face {font-family:瀹嬩綋; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:Century; panose-1:2 4 6 4 5 5 5 2 3 4; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:647 0 0 0 159 0;} @font-face {font-family:"MS PGothic"; panose-1:2 11 6 0 7 2 5 8 2 4; mso-font-charset:128; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-1610612033 1757936891 16 0 131231 0;} @font-face {font-family:Verdana; panose-1:2 11 6 4 3 5 4 4 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:536871559 0 0 0 415 0;} @font-face {font-family:"\@MS PGothic"; panose-1:2 11 6 0 7 2 5 8 2 4; mso-font-charset:128; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-1610612033 1757936891 16 0 131231 0;} @font-face {font-family:"\@瀹嬩綋"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"\@MS Mincho"; panose-1:2 2 6 9 4 2 5 8 3 4; mso-font-charset:128; mso-generic-font-family:modern; mso-font-pitch:fixed; mso-font-signature:-1610612033 1757936891 16 0 131231 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:Century; mso-fareast-font-family:"MS Mincho"; mso-bidi-font-family:"Times New Roman"; mso-font-kerning:1.0pt; mso-fareast-language:JA;} h1 {mso-margin-top-alt:auto; margin-right:0cm; mso-margin-bottom-alt:auto; margin-left:0cm; mso-pagination:widow-orphan; mso-outline-level:1; font-size:24.0pt; font-family:"MS PGothic"; mso-bidi-font-family:"MS PGothic"; mso-fareast-language:JA;} p.MsoHeader, li.MsoHeader, div.MsoHeader {margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; tab-stops:center 212.6pt right 425.2pt; layout-grid-mode:char; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:Century; mso-fareast-font-family:"MS Mincho"; mso-bidi-font-family:"Times New Roman"; mso-font-kerning:1.0pt; mso-fareast-language:JA;} p.MsoFooter, li.MsoFooter, div.MsoFooter {margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; tab-stops:center 212.6pt right 425.2pt; layout-grid-mode:char; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:Century; mso-fareast-font-family:"MS Mincho"; mso-bidi-font-family:"Times New Roman"; mso-font-kerning:1.0pt; mso-fareast-language:JA;} a:link, span.MsoHyperlink {color:blue; text-decoration:underline; text-underline:single;} a:visited, span.MsoHyperlinkFollowed {color:purple; text-decoration:underline; text-underline:single;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:595.3pt 841.9pt; margin:99.25pt 3.0cm 3.0cm 3.0cm; mso-header-margin:42.55pt; mso-footer-margin:49.6pt; mso-paper-source:0; layout-grid:18.0pt;} div.Section1 {page:Section1;} --> </style> <p>榪欎竴緋誨垪鏂囩珷浠嬬粛Microsoft Visual Studio 2010 涓敮鎸佺殑C++ 0x鐗規э紝鐩墠鏈変笁閮ㄥ垎銆?<br><a title="VC10涓殑C++0x鐗規?part 1" target=_blank>Part 1</a> 錛氫粙緇嶄簡Lambdas錛?璧嬩簣鏂版剰涔夌殑auto錛屼互鍙?static_assert錛?<br>Part 2( <a title="VC10涓殑C++0x鐗規?part 2 絎竴閮ㄥ垎" href="http://m.shnenglu.com/kesalin/archive/2009/05/28/85983.html" target=_blank>涓</a> , <a title="VC10涓殑C++0x鐗規?part 2 絎簩閮ㄥ垎" href="http://m.shnenglu.com/kesalin/archive/2009/06/04/86720.html" target=_blank>浜?/a> , <a title="VC10涓殑C++0x鐗規?part 2 絎笁閮ㄥ垎 " href="http://m.shnenglu.com/kesalin/archive/2009/06/05/86851.html" target=_blank>涓?/a> )錛氫粙緇嶄簡鍙沖煎紩鐢紙Rvalue References錛夛紱 <br><a title="VC10涓殑C++0x鐗規?part 3" href="http://m.shnenglu.com/kesalin/archive/2009/06/07/86960.html" target=_blank>Part 3</a>錛氫粙緇嶄簡琛ㄨ揪寮忕被鍨嬶紙decltype錛?br><br>VC10涓殑C++0x鐗規?Part 1,2,3 璇戞枃鎵撳寘涓嬭澆錛坉oc 鍜?pdf 鏍煎紡錛夛細 <a title="VC10涓殑C++0x鐗規э紙Part 1,2,3錛夎瘧鏂嘾oc鍜宲df鏂囨。" href="http://m.shnenglu.com/Files/kesalin/Cplusplus0x_in_VC10.zip" target=_blank>鐐規涓嬭澆</a></p> </div> <br> <object id=ieooui classid=clsid:38481807-ca0e-42d2-bf39-b33af135cc4d></object><style> st1\:*{behavior:url(#ieooui) } </style>鏈枃涓?Part 2 絎簩欏點? <p style="FONT-FAMILY: 瀹嬩綋"></p> <br style="FONT-FAMILY: 瀹嬩綋"> <meta content=Word.Document name=ProgId> <meta content="Microsoft Word 11" name=Generator> <meta content="Microsoft Word 11" name=Originator> <link style="FONT-FAMILY: 瀹嬩綋" href="file:///C:%5CDOCUME%7E1%5CLUO%7E1.ZHA%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C02%5Cclip_filelist.xml" rel=File-List><style> <!-- /* Font Definitions */ @font-face {font-family:"錛汲 鏄庢湞"; panose-1:2 2 6 9 4 2 5 8 3 4; mso-font-alt:"MS Mincho"; mso-font-charset:128; mso-generic-font-family:roman; mso-font-pitch:fixed; mso-font-signature:-1610612033 1757936891 16 0 131231 0;} @font-face {font-family:SimSun; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:瀹嬩綋; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:Century; panose-1:2 4 6 4 5 5 5 2 3 4; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:647 0 0 0 159 0;} @font-face {font-family:"錛汲 錛般偞銈楓儍銈?; panose-1:2 11 6 0 7 2 5 8 2 4; mso-font-charset:128; mso-generic-font-family:modern; mso-font-pitch:variable; mso-font-signature:-1610612033 1757936891 16 0 131231 0;} @font-face {font-family:"\@SimSun"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"\@錛汲 錛般偞銈楓儍銈?; panose-1:2 11 6 0 7 2 5 8 2 4; mso-font-charset:128; mso-generic-font-family:modern; mso-font-pitch:variable; mso-font-signature:-1610612033 1757936891 16 0 131231 0;} @font-face {font-family:"\@錛汲 鏄庢湞"; panose-1:2 2 6 9 4 2 5 8 3 4; mso-font-charset:128; mso-generic-font-family:roman; mso-font-pitch:fixed; mso-font-signature:-1610612033 1757936891 16 0 131231 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0mm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:Century; mso-fareast-font-family:"錛汲 鏄庢湞"; mso-bidi-font-family:"Times New Roman"; mso-font-kerning:1.0pt;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:612.0pt 792.0pt; margin:99.25pt 30.0mm 30.0mm 30.0mm; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} --> </style> <p style="FONT-FAMILY: 瀹嬩綋"><strong>move </strong><strong>璇剰錛氫粠</strong><strong> lvalue </strong><strong>縐誨姩</strong></p> <p style="FONT-FAMILY: 瀹嬩綋"><br></p> <p style="FONT-FAMILY: 瀹嬩綋">鐜板湪錛屽鏋滀綘鍠滄鐢ㄦ嫹璐濊祴鍊煎嚱鏁版潵瀹炵幇浣犵殑鎷瘋礉鏋勯犲嚱鏁拌鎬庢牱鍋氬憿錛岄偅浣犱篃鍙兘璇曞浘鐢?move 鎷瘋礉璧嬪煎嚱鏁版潵瀹炵幇 move 鏋勯犲嚱鏁般傝繖鏍蜂綔鏄彲浠ョ殑錛屼絾鏄綘寰楀皬蹇冦備笅闈㈠氨鏄竴涓敊璇殑瀹炵幇錛?/p> <p style="FONT-FAMILY: 瀹嬩綋"> </p> <p style="FONT-FAMILY: courier new">C:\Temp>type unified_wrong.cpp</p> <p style="FONT-FAMILY: courier new">#include <stddef.h></p> <p style="FONT-FAMILY: courier new">#include <iostream></p> <p style="FONT-FAMILY: courier new">#include <ostream></p> <p style="FONT-FAMILY: courier new">using namespace std;</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">class remote_integer {</p> <p style="FONT-FAMILY: courier new">public:</p> <p style="FONT-FAMILY: courier new">    remote_integer() {</p> <p style="FONT-FAMILY: courier new">        cout << "Default constructor." << endl;</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">        m_p = NULL;</p> <p style="FONT-FAMILY: courier new">    }</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    explicit remote_integer(const int n) {</p> <p style="FONT-FAMILY: courier new">        cout << "Unary constructor." << endl;</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">        m_p = new int(n);</p> <p style="FONT-FAMILY: courier new">    }</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    remote_integer(const remote_integer& other) {</p> <p style="FONT-FAMILY: courier new">        cout << "Copy constructor." << endl;</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">        m_p = NULL;</p> <p style="FONT-FAMILY: courier new">        *this = other;</p> <p style="FONT-FAMILY: courier new">    }</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">#ifdef MOVABLE</p> <p style="FONT-FAMILY: courier new">    remote_integer(remote_integer&& other) {</p> <p style="FONT-FAMILY: courier new">        cout << "MOVE CONSTRUCTOR." << endl;</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">        m_p = NULL;</p> <p style="FONT-FAMILY: courier new">        *this = other; // WRONG</p> <p style="FONT-FAMILY: courier new">    }</p> <p style="FONT-FAMILY: courier new">#endif // #ifdef MOVABLE</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    remote_integer& operator=(const remote_integer& other) {</p> <p style="FONT-FAMILY: courier new">        cout << "Copy assignment operator." << endl;</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">        if (this != &other) {</p> <p style="FONT-FAMILY: courier new">            delete m_p;</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">            if (other.m_p) {</p> <p style="FONT-FAMILY: courier new">                m_p = new int(*other.m_p);</p> <p style="FONT-FAMILY: courier new">            } else {</p> <p style="FONT-FAMILY: courier new">                m_p = NULL;</p> <p style="FONT-FAMILY: courier new">            }</p> <p style="FONT-FAMILY: courier new">        }</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">        return *this;</p> <p style="FONT-FAMILY: courier new">    }</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">#ifdef MOVABLE</p> <p style="FONT-FAMILY: courier new">    remote_integer& operator=(remote_integer&& other) {</p> <p style="FONT-FAMILY: courier new">        cout << "MOVE ASSIGNMENT OPERATOR." << endl;</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">        if (this != &other) {</p> <p style="FONT-FAMILY: courier new">            delete m_p;</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">            m_p = other.m_p;</p> <p style="FONT-FAMILY: courier new">            other.m_p = NULL;</p> <p style="FONT-FAMILY: courier new">        }</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">        return *this;</p> <p style="FONT-FAMILY: courier new">    }</p> <p style="FONT-FAMILY: courier new">#endif // #ifdef MOVABLE</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    ~remote_integer() {</p> <p style="FONT-FAMILY: courier new">        cout << "Destructor." << endl;</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">        delete m_p;</p> <p style="FONT-FAMILY: courier new">    }</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    int get() const {</p> <p style="FONT-FAMILY: courier new">        return m_p ? *m_p : 0;</p> <p style="FONT-FAMILY: courier new">    }</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">private:</p> <p style="FONT-FAMILY: courier new">    int * m_p;</p> <p style="FONT-FAMILY: courier new">};</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">remote_integer frumple(const int n) {</p> <p style="FONT-FAMILY: courier new">    if (n == 1729) {</p> <p style="FONT-FAMILY: courier new">        return remote_integer(1729);</p> <p style="FONT-FAMILY: courier new">    }</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    remote_integer ret(n * n);</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    return ret;</p> <p style="FONT-FAMILY: courier new">}</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">int main() {</p> <p style="FONT-FAMILY: courier new">    remote_integer x = frumple(5);</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    cout << x.get() << endl;</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    remote_integer y = frumple(1729);</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    cout << y.get() << endl;</p> <p style="FONT-FAMILY: courier new">}</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">C:\Temp>cl /EHsc /nologo /W4 /O2 unified_wrong.cpp</p> <p style="FONT-FAMILY: courier new">unified_wrong.cpp</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">C:\Temp>unified_wrong</p> <p style="FONT-FAMILY: courier new">Unary constructor.</p> <p style="FONT-FAMILY: courier new">Copy constructor.</p> <p style="FONT-FAMILY: courier new">Copy assignment operator.</p> <p style="FONT-FAMILY: courier new">Destructor.</p> <p style="FONT-FAMILY: courier new">25</p> <p style="FONT-FAMILY: courier new">Unary constructor.</p> <p style="FONT-FAMILY: courier new">1729</p> <p style="FONT-FAMILY: courier new">Destructor.</p> <p style="FONT-FAMILY: courier new">Destructor.</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">C:\Temp>cl /EHsc /nologo /W4 /O2 /DMOVABLE unified_wrong.cpp</p> <p style="FONT-FAMILY: courier new">unified_wrong.cpp</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">C:\Temp>unified_wrong</p> <p style="FONT-FAMILY: courier new">Unary constructor.</p> <p style="FONT-FAMILY: courier new">MOVE CONSTRUCTOR.</p> <p style="FONT-FAMILY: courier new">Copy assignment operator.</p> <p style="FONT-FAMILY: courier new">Destructor.</p> <p style="FONT-FAMILY: courier new">25</p> <p style="FONT-FAMILY: courier new">Unary constructor.</p> <p style="FONT-FAMILY: courier new">1729</p> <p style="FONT-FAMILY: courier new">Destructor.</p> <p style="FONT-FAMILY: courier new">Destructor.</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: 瀹嬩綋">(緙栬瘧鍣ㄥ湪榪欓噷榪涜浜嗚繑鍥炲間紭鍖?RVO)錛屼絾涓嶆槸鍏峰悕榪斿洖鍊間紭鍖?NRVO)銆傚氨鍍忔垜涔嬪墠鎻愬埌鐨勶紝鏈変簺鎷瘋礉鏋勯犲嚱鏁拌 RVO 鎴?NRVO 浼樺寲鎺変簡錛屼絾緙栬瘧鍣ㄥ茍涓嶆繪槸鑳藉鍋氳繖鏍風殑浼樺寲錛岃繖鏃跺墿浣欑殑灝辯敱 move 鏋勯犲嚱鏁版潵浼樺寲銆?</p> <p style="FONT-FAMILY: 瀹嬩綋"> </p> <p style="FONT-FAMILY: 瀹嬩綋">move 鏋勯犲嚱鏁頒腑鏍囪涓?WRONG 鐨勯偅涓琛岋紝璋冪敤浜嗘嫹璐濊祴鍊煎嚱鏁幫紝緙栬瘧鑳介氳繃涔熻兘榪愯錛屼絾榪欒繚鑳屼簡 move 鏋勯犲嚱鏁扮殑鏈剰銆傦紙璇戞敞錛氬洜涓洪偅涓嫹璐濊祴鍊煎嚱鏁板彧鏄繘琛屾櫘閫氱殑鎷瘋礉璧嬪鹼紝鑰屼笉鏄?move 璧嬪鹼紒錛?/p> <p style="FONT-FAMILY: 瀹嬩綋"> </p> <p style="FONT-FAMILY: 瀹嬩綋">榪欐槸鎬庝箞鍥炰簨鍛紵璁頒綇錛氬湪C++98/03涓紝鍏峰悕 lvalue 寮曠敤鏄乏鍊?緇欏畾璇彞 int& r = *p; r 鏄?lvalue)錛屼笉鍏峰悕 lvalue 寮曠敤榪樻槸宸﹀?緇欏畾璇彞 vector<int> v(10, 1729)錛?v[0] 榪斿洖 int&錛?浣犲彲浠ュ榪欎釜涓嶅叿鍚?lvalue 寮曠敤鍙栧潃)銆備絾鏄?rvalue 寮曠敤灝變笉涓鏍蜂簡錛?/p> <p style="FONT-FAMILY: 瀹嬩綋"> </p> <p style="FONT-FAMILY: 瀹嬩綋"><strong>飩?/strong><strong> </strong><strong>鍏峰悕</strong><strong> </strong><strong>lvalue</strong><strong> </strong><strong>寮曠敤鏄?/strong><strong> </strong><strong>lvalue</strong><strong>銆?/strong><strong></strong></p> <p style="FONT-FAMILY: 瀹嬩綋"><strong>飩?/strong><strong> </strong><strong>涓嶅叿鍚?/strong><strong> rvalue</strong><strong> </strong><strong>寮曠敤鏄?/strong><strong> </strong><strong>rvalue</strong><strong>銆?/strong><strong></strong></p> <p style="FONT-FAMILY: 瀹嬩綋"> </p> <p style="FONT-FAMILY: 瀹嬩綋">涓涓叿鍚?rvalue 寮曠敤鏄竴涓?lvalue 鏄洜涓哄彲浠ュ瀹冩柦鍔犲閲嶆搷浣滐紝閲嶅浣跨敤銆傜浉鍙嶏紝濡傛灉瀹冩槸涓涓?ravlue 鐨勮瘽錛岄偅涔堝瀹冩柦鍔犵殑絎竴涓搷浣滆兘澶?#8220;紿冨彇”瀹冿紝鑰屽悗緇搷浣滃氨娌℃満浼氫簡銆傝繖閲岀殑“紿冨彇”鏄涓嶄細琚療瑙夊埌錛屾墍浠ヨ繖鏄涓嶉氱殑銆傚彟涓鏂歸潰錛屼笉鍏峰悕 rvalue 寮曠敤涓嶈兘琚噸澶嶄嬌鐢紝鎵浠ュ畠浠嶄繚鎸佸彸鍊?rvalueness)璇剰銆?/p> <p style="FONT-FAMILY: 瀹嬩綋"> </p> <p style="FONT-FAMILY: 瀹嬩綋">濡傛灉浣犵湡鐨勬墦綆楃敤 move 璧嬪煎嚱鏁版潵瀹炵幇 move 鏋勯犲嚱鏁幫紝浣犻渶瑕佷粠 lvalue move錛屽氨鍍忔槸浠?rvalue move 涓鏍楓侰++0x <utility> 涓殑 std::move() 鍏峰榪欐牱鐨勮兘鍔涳紝VC10灝嗕細鏈夎繖涓紙瀹為檯涓婏紝寮鍙戠増涓凡緇忔湁浜嗭級錛屼絾VC10 TCP鐗堣繕娌℃湁錛屾墍浠ユ垜浼氭暀浣犱粠澶村仛璧鳳細</p> <p style="FONT-FAMILY: 瀹嬩綋"> </p> <p style="FONT-FAMILY: courier new">C:\Temp>type unified_right.cpp</p> <p style="FONT-FAMILY: courier new">#include <stddef.h></p> <p style="FONT-FAMILY: courier new">#include <iostream></p> <p style="FONT-FAMILY: courier new">#include <ostream></p> <p style="FONT-FAMILY: courier new">using namespace std;</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">template <typename T> struct RemoveReference {</p> <p style="FONT-FAMILY: courier new">     typedef T type;</p> <p style="FONT-FAMILY: courier new">};</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">template <typename T> struct RemoveReference<T&> {</p> <p style="FONT-FAMILY: courier new">     typedef T type;</p> <p style="FONT-FAMILY: courier new">};</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">template <typename T> struct RemoveReference<T&&> {</p> <p style="FONT-FAMILY: courier new">     typedef T type;</p> <p style="FONT-FAMILY: courier new">};</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">template <typename T> typename RemoveReference<T>::type&& Move(T&& t) {</p> <p style="FONT-FAMILY: courier new">    return t;</p> <p style="FONT-FAMILY: courier new">}</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">class remote_integer {</p> <p style="FONT-FAMILY: courier new">public:</p> <p style="FONT-FAMILY: courier new">    remote_integer() {</p> <p style="FONT-FAMILY: courier new">        cout << "Default constructor." << endl;</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">        m_p = NULL;</p> <p style="FONT-FAMILY: courier new">    }</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    explicit remote_integer(const int n) {</p> <p style="FONT-FAMILY: courier new">        cout << "Unary constructor." << endl;</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">        m_p = new int(n);</p> <p style="FONT-FAMILY: courier new">    }</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    remote_integer(const remote_integer& other) {</p> <p style="FONT-FAMILY: courier new">        cout << "Copy constructor." << endl;</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">        m_p = NULL;</p> <p style="FONT-FAMILY: courier new">        *this = other;</p> <p style="FONT-FAMILY: courier new">    }</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">#ifdef MOVABLE</p> <p style="FONT-FAMILY: courier new">    remote_integer(remote_integer&& other) {</p> <p style="FONT-FAMILY: courier new">        cout << "MOVE CONSTRUCTOR." << endl;</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">        m_p = NULL;</p> <p style="FONT-FAMILY: courier new">        *this = Move(other); // RIGHT</p> <p style="FONT-FAMILY: courier new">    }</p> <p style="FONT-FAMILY: courier new">#endif // #ifdef MOVABLE</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    remote_integer& operator=(const remote_integer& other) {</p> <p style="FONT-FAMILY: courier new">        cout << "Copy assignment operator." << endl;</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">        if (this != &other) {</p> <p style="FONT-FAMILY: courier new">            delete m_p;</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">            if (other.m_p) {</p> <p style="FONT-FAMILY: courier new">                m_p = new int(*other.m_p);</p> <p style="FONT-FAMILY: courier new">            } else {</p> <p style="FONT-FAMILY: courier new">                m_p = NULL;</p> <p style="FONT-FAMILY: courier new">            }</p> <p style="FONT-FAMILY: courier new">        }</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">        return *this;</p> <p style="FONT-FAMILY: courier new">    }</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">#ifdef MOVABLE</p> <p style="FONT-FAMILY: courier new">    remote_integer& operator=(remote_integer&& other) {</p> <p style="FONT-FAMILY: courier new">        cout << "MOVE ASSIGNMENT OPERATOR." << endl;</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">        if (this != &other) {</p> <p style="FONT-FAMILY: courier new">            delete m_p;</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">            m_p = other.m_p;</p> <p style="FONT-FAMILY: courier new">            other.m_p = NULL;</p> <p style="FONT-FAMILY: courier new">        }</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">        return *this;</p> <p style="FONT-FAMILY: courier new">    }</p> <p style="FONT-FAMILY: courier new">#endif // #ifdef MOVABLE</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    ~remote_integer() {</p> <p style="FONT-FAMILY: courier new">        cout << "Destructor." << endl;</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">        delete m_p;</p> <p style="FONT-FAMILY: courier new">    }</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    int get() const {</p> <p style="FONT-FAMILY: courier new">        return m_p ? *m_p : 0;</p> <p style="FONT-FAMILY: courier new">    }</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">private:</p> <p style="FONT-FAMILY: courier new">    int * m_p;</p> <p style="FONT-FAMILY: courier new">};</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">remote_integer frumple(const int n) {</p> <p style="FONT-FAMILY: courier new">    if (n == 1729) {</p> <p style="FONT-FAMILY: courier new">        return remote_integer(1729);</p> <p style="FONT-FAMILY: courier new">    }</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    remote_integer ret(n * n);</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    return ret;</p> <p style="FONT-FAMILY: courier new">}</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">int main() {</p> <p style="FONT-FAMILY: courier new">    remote_integer x = frumple(5);</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    cout << x.get() << endl;</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    remote_integer y = frumple(1729);</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    cout << y.get() << endl;</p> <p style="FONT-FAMILY: courier new">}</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">C:\Temp>cl /EHsc /nologo /W4 /O2 /DMOVABLE unified_right.cpp</p> <p style="FONT-FAMILY: courier new">unified_right.cpp</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">C:\Temp>unified_right</p> <p style="FONT-FAMILY: courier new">Unary constructor.</p> <p style="FONT-FAMILY: courier new">MOVE CONSTRUCTOR.</p> <p style="FONT-FAMILY: courier new">MOVE ASSIGNMENT OPERATOR.</p> <p style="FONT-FAMILY: courier new">Destructor.</p> <p style="FONT-FAMILY: courier new">25</p> <p style="FONT-FAMILY: courier new">Unary constructor.</p> <p style="FONT-FAMILY: courier new">1729</p> <p style="FONT-FAMILY: courier new">Destructor.</p> <p style="FONT-FAMILY: courier new">Destructor.</p> <p style="FONT-FAMILY: 瀹嬩綋"> </p> <p style="FONT-FAMILY: 瀹嬩綋">錛堟垜灝嗕氦鏇夸嬌鐢?std::move() 鍜屾垜鑷繁鐨?Move()錛屽洜涓哄畠浠殑瀹炵幇鏄瓑浠風殑錛?std::move() 鏄庢牱宸ヤ綔鐨勫憿錛熺洰鍓嶏紝鎴戝彧鑳借窡浣犺榪欐槸“欖旀硶”銆傦紙鍚庨潰浼氭湁瀹屾暣鐨勮В閲婏紝騫朵笉澶嶆潅錛屼絾瀹冧笌妯℃澘鍙傛暟鎺ㄥ鍜屽紩鐢ㄦ姌鍙狅紙reference collapsing錛岃瘧娉細寮曠敤鐨勫紩鐢級鏈?鍏籌紝鍚庨潰璁插畬緹庤漿鍙戠殑鏃跺欐垜浠繕浼氶亣鍒拌繖涓や釜涓滆タ錛夈傛垜鍙互鐢ㄤ竴涓叿浣撶殑渚嬪瓙鏉ョ暐榪?#8220;欖旀硶”錛氱粰瀹氫竴涓?string 綾誨瀷鐨勫乏鍊鹼紝鍍忓墠闈㈤噸杞藉喅璁緥瀛愪腑鐨?up 錛宻td::move(up) 璋冪敤 string&& std::move(string&)錛岃繖涓嚱鏁拌繑鍥炰竴涓笉鍏峰悕鐨?rvalue 寮曠敤錛屽畠鏄竴涓?rvalue銆傜粰瀹氫竴涓?string 綾誨瀷鐨?rvalue錛屽儚鍓嶉潰閲嶈澆鍐寵渚嬪瓙涓殑 strange()錛?std::move(strange()) 璋冪敤 string&& std::move(string&&)錛屽悓鏍瘋繖涓嚱鏁拌繕鏄繑鍥炰竴涓笉鍏峰悕鐨?rvalue錛岃繕鏄?rvalue銆?/p> <p style="FONT-FAMILY: 瀹嬩綋"> </p> <p style="FONT-FAMILY: 瀹嬩綋">std::move() 闄や簡璁╀綘鑳界敤 move 澶嶅埗鍑芥暟鏉ュ疄鐜?move 鏋勯犲嚱鏁頒箣澶栵紝榪樿兘鍦ㄥ叾浠栧湴鏂瑰彂鎸ヤ綔鐢ㄣ傛棤璁轟綍鏃訛紝鍙浣犳湁涓涓乏鍊鹼紝鑰屽畠鐨勫間篃涓嶅啀閲嶈浜嗭紙渚嬪錛屽畠灝嗚閿姣佹垨琚祴鍊鹼級錛屼綘灝卞彲浠ヤ嬌鐢?std::move(浣犵殑宸﹀艱〃杈懼紡) 鏉ヤ嬌鐢?move 璇剰銆?/p> <p style="FONT-FAMILY: 瀹嬩綋"> </p> <p style="FONT-FAMILY: 瀹嬩綋"><strong>move </strong><strong>璇剰錛氬彲縐誨姩鎴愬憳錛?/strong><strong>movable member)</strong></p> <p style="FONT-FAMILY: 瀹嬩綋"><br></p> <p style="FONT-FAMILY: 瀹嬩綋">C++0x 鐨勬爣鍑嗙被鍨嬶紙鍍?vector, string, regex錛?閮芥湁 move 鏋勯犲嚱鏁板拰 move 璧嬪煎嚱鏁般傝屼笖鎴戜滑涔熷凡緇忕湅鍒頒簡濡備綍鍦ㄦ垜浠嚜宸辯殑綾諱腑閫氳繃鎵嬪姩綆$悊璧勬簮鏉ュ疄鐜?move 璇剰錛堝儚鍓嶉潰鐨?remote_integer 綾伙級銆傚鏋滅被涓寘鍚彲縐誨姩鏁版嵁鎴愬憳錛堝儚 vector, string, regex, remote_integer 錛夋椂璇ユ庝箞鍔炲憿錛熺紪璇戝櫒涓嶄細鑷姩甯垜浠嚜鍔ㄤ駭鐢?move 鏋勯犲嚱鏁板拰 move 璧嬪煎嚱鏁幫紝鎵浠ユ垜浠繀欏繪墜鍔ㄧ紪鍐欏畠浠傚緢騫歌繍錛屾湁浜?std::move() 緙栧啓瀹冧滑鏄緢瀹規槗鐨勩?/p> <p style="FONT-FAMILY: 瀹嬩綋"> </p> <p style="FONT-FAMILY: courier new">C:\Temp>type point.cpp</p> <p style="FONT-FAMILY: courier new">#include <stddef.h></p> <p style="FONT-FAMILY: courier new">#include <iostream></p> <p style="FONT-FAMILY: courier new">#include <ostream></p> <p style="FONT-FAMILY: courier new">using namespace std;</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">template <typename T> struct RemoveReference {</p> <p style="FONT-FAMILY: courier new">     typedef T type;</p> <p style="FONT-FAMILY: courier new">};</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">template <typename T> struct RemoveReference<T&> {</p> <p style="FONT-FAMILY: courier new">     typedef T type;</p> <p style="FONT-FAMILY: courier new">};</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">template <typename T> struct RemoveReference<T&&> {</p> <p style="FONT-FAMILY: courier new">     typedef T type;</p> <p style="FONT-FAMILY: courier new">};</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">template <typename T> typename RemoveReference<T>::type&& Move(T&& t) {</p> <p style="FONT-FAMILY: courier new">    return t;</p> <p style="FONT-FAMILY: courier new">}</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">class remote_integer {</p> <p style="FONT-FAMILY: courier new">public:</p> <p style="FONT-FAMILY: courier new">    remote_integer() {</p> <p style="FONT-FAMILY: courier new">        cout << "Default constructor." << endl;</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">        m_p = NULL;</p> <p style="FONT-FAMILY: courier new">    }</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    explicit remote_integer(const int n) {</p> <p style="FONT-FAMILY: courier new">        cout << "Unary constructor." << endl;</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">        m_p = new int(n);</p> <p style="FONT-FAMILY: courier new">    }</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    remote_integer(const remote_integer& other) {</p> <p style="FONT-FAMILY: courier new">        cout << "Copy constructor." << endl;</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">        if (other.m_p) {</p> <p style="FONT-FAMILY: courier new">            m_p = new int(*other.m_p);</p> <p style="FONT-FAMILY: courier new">        } else {</p> <p style="FONT-FAMILY: courier new">            m_p = NULL;</p> <p style="FONT-FAMILY: courier new">        }</p> <p style="FONT-FAMILY: courier new">    }</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    remote_integer(remote_integer&& other) {</p> <p style="FONT-FAMILY: courier new">        cout << "MOVE CONSTRUCTOR." << endl;</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">        m_p = other.m_p;</p> <p style="FONT-FAMILY: courier new">        other.m_p = NULL;</p> <p style="FONT-FAMILY: courier new">    }</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    remote_integer& operator=(const remote_integer& other) {</p> <p style="FONT-FAMILY: courier new">        cout << "Copy assignment operator." << endl;</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">        if (this != &other) {</p> <p style="FONT-FAMILY: courier new">            delete m_p;</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">            if (other.m_p) {</p> <p style="FONT-FAMILY: courier new">                m_p = new int(*other.m_p);</p> <p style="FONT-FAMILY: courier new">            } else {</p> <p style="FONT-FAMILY: courier new">                m_p = NULL;</p> <p style="FONT-FAMILY: courier new">            }</p> <p style="FONT-FAMILY: courier new">        }</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">        return *this;</p> <p style="FONT-FAMILY: courier new">    }</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    remote_integer& operator=(remote_integer&& other) {</p> <p style="FONT-FAMILY: courier new">        cout << "MOVE ASSIGNMENT OPERATOR." << endl;</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">        if (this != &other) {</p> <p style="FONT-FAMILY: courier new">            delete m_p;</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">            m_p = other.m_p;</p> <p style="FONT-FAMILY: courier new">            other.m_p = NULL;</p> <p style="FONT-FAMILY: courier new">        }</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">        return *this;</p> <p style="FONT-FAMILY: courier new">    }</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    ~remote_integer() {</p> <p style="FONT-FAMILY: courier new">        cout << "Destructor." << endl;</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">        delete m_p;</p> <p style="FONT-FAMILY: courier new">    }</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    int get() const {</p> <p style="FONT-FAMILY: courier new">        return m_p ? *m_p : 0;</p> <p style="FONT-FAMILY: courier new">    }</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">private:</p> <p style="FONT-FAMILY: courier new">    int * m_p;</p> <p style="FONT-FAMILY: courier new">};</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">class remote_point {</p> <p style="FONT-FAMILY: courier new">public:</p> <p style="FONT-FAMILY: courier new">    remote_point(const int x_arg, const int y_arg)</p> <p style="FONT-FAMILY: courier new">        : m_x(x_arg), m_y(y_arg) { }</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    remote_point(remote_point&& other)</p> <p style="FONT-FAMILY: courier new">        : m_x(Move(other.m_x)),</p> <p style="FONT-FAMILY: courier new">          m_y(Move(other.m_y)) { }</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    remote_point& operator=(remote_point&& other) {</p> <p style="FONT-FAMILY: courier new">        m_x = Move(other.m_x);</p> <p style="FONT-FAMILY: courier new">        m_y = Move(other.m_y);</p> <p style="FONT-FAMILY: courier new">        return *this;</p> <p style="FONT-FAMILY: courier new">    }</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    int x() const { return m_x.get(); }</p> <p style="FONT-FAMILY: courier new">    int y() const { return m_y.get(); }</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">private:</p> <p style="FONT-FAMILY: courier new">    remote_integer m_x;</p> <p style="FONT-FAMILY: courier new">    remote_integer m_y;</p> <p style="FONT-FAMILY: courier new">};</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">remote_point five_by_five() {</p> <p style="FONT-FAMILY: courier new">    return remote_point(5, 5);</p> <p style="FONT-FAMILY: courier new">}</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">remote_point taxicab(const int n) {</p> <p style="FONT-FAMILY: courier new">    if (n == 0) {</p> <p style="FONT-FAMILY: courier new">        return remote_point(1, 1728);</p> <p style="FONT-FAMILY: courier new">    }</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    remote_point ret(729, 1000);</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    return ret;</p> <p style="FONT-FAMILY: courier new">}</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">int main() {</p> <p style="FONT-FAMILY: courier new">    remote_point p = taxicab(43112609);</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    cout << "(" << p.x() << ", " << p.y() << ")" << endl;</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    p = five_by_five();</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">    cout << "(" << p.x() << ", " << p.y() << ")" << endl;</p> <p style="FONT-FAMILY: courier new">}</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">C:\Temp>cl /EHsc /nologo /W4 /O2 point.cpp</p> <p style="FONT-FAMILY: courier new">point.cpp</p> <p style="FONT-FAMILY: courier new"> </p> <p style="FONT-FAMILY: courier new">C:\Temp>point</p> <p style="FONT-FAMILY: courier new">Unary constructor.</p> <p style="FONT-FAMILY: courier new">Unary constructor.</p> <p style="FONT-FAMILY: courier new">MOVE CONSTRUCTOR.</p> <p style="FONT-FAMILY: courier new">MOVE CONSTRUCTOR.</p> <p style="FONT-FAMILY: courier new">Destructor.</p> <p style="FONT-FAMILY: courier new">Destructor.</p> <p style="FONT-FAMILY: courier new">(729, 1000)</p> <p style="FONT-FAMILY: courier new">Unary constructor.</p> <p style="FONT-FAMILY: courier new">Unary constructor.</p> <p style="FONT-FAMILY: courier new">MOVE ASSIGNMENT OPERATOR.</p> <p style="FONT-FAMILY: courier new">MOVE ASSIGNMENT OPERATOR.</p> <p style="FONT-FAMILY: courier new">Destructor.</p> <p style="FONT-FAMILY: courier new">Destructor.</p> <p style="FONT-FAMILY: courier new">(5, 5)</p> <p style="FONT-FAMILY: courier new">Destructor.</p> <p style="FONT-FAMILY: courier new">Destructor.</p> <p style="FONT-FAMILY: 瀹嬩綋"> </p> <p style="FONT-FAMILY: 瀹嬩綋">鐜板湪浣犵湅鍒板暒錛屾寜鎴愬憳縐誨姩錛坢emberwise move錛夋槸寰堝鏄撳仛鍒扮殑銆傛敞鎰忥紝 remote_point 鐨?move 璧嬪煎嚱鏁版病鏈夎繘琛岃嚜鎴戣祴鍊兼鏌ワ紝鏄洜涓?remote_integer 宸茬粡媯鏌ヨ繃浜嗐備篃瑕佹敞鎰忓埌 remote_point 闅愬紡澹版槑鐨勬嫹璐濇瀯閫犲嚱鏁幫紝鎷瘋礉璧嬪煎嚱鏁板拰鏋愭瀯鍑芥暟閮芥甯歌繍浣溿?/p> <p style="FONT-FAMILY: 瀹嬩綋"> </p> <p style="FONT-FAMILY: 瀹嬩綋">鍒扮幇鍦紝浣犲簲璇ュ move 璇剰宸茬粡闈炲父鐔熸倝浜嗐傦紙甯屾湜涓嶆槸鎶撶媯鍟婏紒錛変負浜嗘祴璇曚綘鏂拌幏寰楃殑榪欎釜涓嶅彲鎬濊鐨勬妧鑳斤紝璇蜂負鍓嶉潰鐨勪緥瀛愬啓涓涓?+() 鎿嶄綔絎﹀嚱鏁板綋浣滅粌涔犲惂銆?/p> <p style="FONT-FAMILY: 瀹嬩綋"> </p> <p style="FONT-FAMILY: 瀹嬩綋">鏈鍚庣殑鎻愰啋錛氬彧瑕佷綘鐨勭被鏀寔 move 璇剰錛屼綘灝卞簲璇ュ疄鐜?move 鏋勯犲嚱鏁板拰 move 璧嬪煎嚱鏁般傚洜涓轟笉浠呬粎鏄綘騫沖父浣跨敤榪欎簺綾繪椂鍙粠 move 璇剰涓幏鍒╋紝 STL 瀹瑰櫒鍜岀畻娉曚篃鑳戒粠涓幏鍒╋紝閫氳繃寤変環鐨?move 鐪佷笅鏄傝吹鐨勬嫹璐濆紑閿銆?/p> <p style="FONT-FAMILY: 瀹嬩綋"><br></p> <p style="FONT-FAMILY: 瀹嬩綋; TEXT-ALIGN: center">(杞澆璇鋒敞鏄庡嚭澶勶紝浣滆呬笌璇戣呬俊鎭紝璇峰嬁鐢ㄤ簬鍟嗕笟鐢ㄩ? </p> <p style="FONT-FAMILY: 瀹嬩綋"><br></p> <p style="FONT-FAMILY: 瀹嬩綋; TEXT-ALIGN: center"> < <a href="http://m.shnenglu.com/kesalin/archive/2009/06/01/86461.html">鍓嶄竴欏?/a>  鍚庝竴欏?><br></p> <br style="FONT-FAMILY: 瀹嬩綋"> <img src ="http://m.shnenglu.com/kesalin/aggbug/86720.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/kesalin/" target="_blank">緗楁湞杈?/a> 2009-06-04 09:37 <a href="http://m.shnenglu.com/kesalin/archive/2009/06/04/86720.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>銆愯瘧銆慥C10涓殑C++0x鐗規?part 2錛?錛?鍙沖煎紩鐢?/title><link>http://m.shnenglu.com/kesalin/archive/2009/06/01/86461.html</link><dc:creator>緗楁湞杈?/dc:creator><author>緗楁湞杈?/author><pubDate>Mon, 01 Jun 2009 12:40:00 GMT</pubDate><guid>http://m.shnenglu.com/kesalin/archive/2009/06/01/86461.html</guid><wfw:comment>http://m.shnenglu.com/kesalin/comments/86461.html</wfw:comment><comments>http://m.shnenglu.com/kesalin/archive/2009/06/01/86461.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://m.shnenglu.com/kesalin/comments/commentRss/86461.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/kesalin/services/trackbacks/86461.html</trackback:ping><description><![CDATA[     鎽樿: 榪欎竴緋誨垪鏂囩珷浠嬬粛Microsoft Visual Studio 2010 涓敮鎸佺殑C++ 0x鐗規э紝鐩墠鏈変笁閮ㄥ垎銆?<br>Part 1錛氫粙緇嶄簡Lambdas錛?璧嬩簣鏂版剰涔夌殑auto錛屼互鍙?static_assert錛?<br>Part 2錛氫粙緇嶄簡鍙沖煎紩鐢紙Rvalue References錛夛紱 <br>Part 3錛氫粙緇嶄簡琛ㄨ揪寮忕被鍨嬶紙decltype錛夈?<br> <br>鏈枃涓篜art 2 鐨勭涓欏點?nbsp; <a href='http://m.shnenglu.com/kesalin/archive/2009/06/01/86461.html'>闃呰鍏ㄦ枃</a><img src ="http://m.shnenglu.com/kesalin/aggbug/86461.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/kesalin/" target="_blank">緗楁湞杈?/a> 2009-06-01 20:40 <a href="http://m.shnenglu.com/kesalin/archive/2009/06/01/86461.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>銆愯瘧銆慥C10涓殑C++0x鐗規?part 1錛歀ambdas錛宎uto錛屼互鍙?static_asserthttp://m.shnenglu.com/kesalin/archive/2009/05/28/85983.html緗楁湞杈?/dc:creator>緗楁湞杈?/author>Thu, 28 May 2009 03:27:00 GMThttp://m.shnenglu.com/kesalin/archive/2009/05/28/85983.htmlhttp://m.shnenglu.com/kesalin/comments/85983.htmlhttp://m.shnenglu.com/kesalin/archive/2009/05/28/85983.html#Feedback14http://m.shnenglu.com/kesalin/comments/commentRss/85983.htmlhttp://m.shnenglu.com/kesalin/services/trackbacks/85983.html闃呰鍏ㄦ枃

]]>
Head First design patterns璇諱功絎旇http://m.shnenglu.com/kesalin/archive/2008/07/20/56714.html緗楁湞杈?/dc:creator>緗楁湞杈?/author>Sun, 20 Jul 2008 15:31:00 GMThttp://m.shnenglu.com/kesalin/archive/2008/07/20/56714.htmlhttp://m.shnenglu.com/kesalin/comments/56714.htmlhttp://m.shnenglu.com/kesalin/archive/2008/07/20/56714.html#Feedback0http://m.shnenglu.com/kesalin/comments/commentRss/56714.htmlhttp://m.shnenglu.com/kesalin/services/trackbacks/56714.html闃呰鍏ㄦ枃

]]>
C璇█澹版槑鐨勪紭鍏堢駭瑙勫垯http://m.shnenglu.com/kesalin/archive/2008/06/30/54992.html緗楁湞杈?/dc:creator>緗楁湞杈?/author>Mon, 30 Jun 2008 15:33:00 GMThttp://m.shnenglu.com/kesalin/archive/2008/06/30/54992.htmlhttp://m.shnenglu.com/kesalin/comments/54992.htmlhttp://m.shnenglu.com/kesalin/archive/2008/06/30/54992.html#Feedback1http://m.shnenglu.com/kesalin/comments/commentRss/54992.htmlhttp://m.shnenglu.com/kesalin/services/trackbacks/54992.html
A 澹版槑浠庡畠鐨勫悕瀛楀紑濮嬭鍙栵紝鐒跺悗鎸夌収浼樺厛綰ч『搴忎緷嬈¤鍙栵紱

B 浼樺厛綰т粠楂樺埌浣庝緷嬈℃槸錛?

B.1 澹版槑涓鎷彿鎷搗鏉ョ殑閭i儴鍒嗭紱

B.2 鍚庣紑鎿嶄綔絎︼細鎷彿()琛ㄧず榪欐槸涓涓嚱鏁幫紝鑰屾柟鎷彿[]琛ㄧず榪欐槸涓涓暟緇勶紱

B.3 鍓嶇紑鎿嶄綔絎︼細鏄熷彿*鏍囪瘑鈥滄寚鍚?..鐨勬寚閽堚濓紱

C 濡傛灉const鍜?鎴栬?volatile鍏抽敭瀛楃殑鍚庨潰绱ц窡綾誨瀷璇存槑絎?濡俰nt錛宭ong絳?錛岄偅涔堝畠浣滅敤浜庣被鍨嬭鏄庣錛屽湪鍏朵粬鎯呭喌涓嬶紝const鍜?鎴?volatile鍏抽敭瀛椾綔鐢ㄤ簬瀹冨乏杈圭揣閭葷殑鎸囬拡鏄熷彿銆?
  闃呰鍏ㄦ枃

]]>
銆愯瘧銆戝湪C++涓嬌鐢↙UAhttp://m.shnenglu.com/kesalin/archive/2008/06/17/53688.html緗楁湞杈?/dc:creator>緗楁湞杈?/author>Tue, 17 Jun 2008 04:38:00 GMThttp://m.shnenglu.com/kesalin/archive/2008/06/17/53688.htmlhttp://m.shnenglu.com/kesalin/comments/53688.htmlhttp://m.shnenglu.com/kesalin/archive/2008/06/17/53688.html#Feedback0http://m.shnenglu.com/kesalin/comments/commentRss/53688.htmlhttp://m.shnenglu.com/kesalin/services/trackbacks/53688.html
鍘熸枃閾炬帴錛歨ttp://www.spheregames.com/index.php?p=templates/pages/tutorials

浣滆咃細http://www.spheregames.com

緲昏瘧錛氶椋樼櫧浜戯紙http://m.shnenglu.com/kesalin 錛?



璇戞敞錛氱炕璇戞湰鏂囧茍鏈幏寰楀師浣滆呯殑璁稿彲錛岀炕璇戞湰鏂囨潵浠呬緵涓漢瀛︿範娑堥仯錛屾晠璋㈠嵈杞澆銆?

鍘熸枃涓殑紺轟緥浠g爜姹插彇浜嗐婃父鎴忕紪紼嬬簿綺?5銆嬩腑Matthew Harmon鍐欑殑 鈥淏uilding LUA into Games鈥濅竴鏂囩殑鎯蟲硶涓庨儴鍒嗕唬鐮佸疄鐜幫紝鎴戝皢鈥淏uilding LUA into Games鈥濅竴鏂囩殑紺轟緥浠g爜搴旂敤鍒版渶鏂扮殑LUA鐗堟湰錛屼篃鎵撳寘璐村湪榪欓噷錛屼緵澶у鍙傝冦?

Using LUA with C++錛氱ず渚嬩唬鐮佷笅杞?

Building LUA into Gam  闃呰鍏ㄦ枃

]]>
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲欧美日韩高清| 国产精品网红福利| av成人福利| 99国产一区| 一二三区精品福利视频| 亚洲尤物视频在线| 欧美在线地址| 免费观看一区| 欧美日韩中文字幕在线| 国产酒店精品激情| 在线观看日韩www视频免费| 亚洲国产一二三| 99视频精品| 午夜久久电影网| 免费中文日韩| 在线视频你懂得一区二区三区| 亚洲一区免费| 久久日韩精品| 国产精品欧美激情| 91久久精品日日躁夜夜躁欧美| 亚洲天堂免费在线观看视频| 午夜日韩福利| 亚洲国内欧美| 亚洲亚洲精品在线观看| 久久久久国产免费免费| 欧美视频手机在线| 亚洲电影免费| 久久福利影视| 一区二区三区精品| 欧美成人一区二区在线| 国产日韩一区| 一区二区三区欧美在线| 免费久久99精品国产自在现线| 99这里只有精品| 欧美成人国产| 一区二区视频免费完整版观看| 亚洲一区二区三区四区五区黄 | 国产一区自拍视频| 日韩亚洲成人av在线| 久久亚洲高清| 国产综合精品一区| 欧美精品一区二区在线播放| 国产亚洲欧美另类中文| 一区二区三区欧美激情| 亚洲高清在线精品| 久久九九国产精品怡红院| 国产精品嫩草影院av蜜臀| 日韩视频在线你懂得| 欧美sm重口味系列视频在线观看| 午夜欧美大片免费观看| 欧美日韩国产美女| 日韩视频在线观看免费| 欧美激情一级片一区二区| 久久国产婷婷国产香蕉| 国产日韩欧美电影在线观看| 午夜精品在线| 午夜久久美女| 国产一区二区三区久久悠悠色av| 午夜亚洲福利| 欧美亚洲免费高清在线观看| 国产精品综合网站| 亚洲欧美精品| 午夜精品在线观看| 狠狠色狠狠色综合日日小说| 久久天天躁狠狠躁夜夜爽蜜月| 欧美一区二区精品久久911| 国产亚洲欧美aaaa| 欧美大片在线观看| 欧美刺激性大交免费视频| 亚洲精品久久久久中文字幕欢迎你| 欧美成人亚洲成人| 欧美精品一区二区三区久久久竹菊 | 国产精品99久久久久久www| 欧美日韩亚洲一区二区三区在线观看| 日韩一级网站| 亚洲自拍偷拍网址| 在线观看欧美一区| 亚洲人成小说网站色在线| 欧美亚一区二区| 久久夜色精品国产欧美乱极品| 久久久久国产免费免费| 99国产精品99久久久久久| 在线视频欧美日韩精品| 国内精品国产成人| 91久久精品美女| 国产伦精品一区二区三区四区免费 | 日韩视频在线免费| 亚洲一区二区三| 亚洲高清不卡在线| 99视频精品在线| 国产一区二区三区精品久久久| 免费一区视频| 欧美午夜精品理论片a级大开眼界| 欧美日韩午夜| 亚洲免费黄色| 亚洲国产一二三| 国产精品久久久久久久7电影 | 欧美一区二区三区婷婷月色| 欧美在线首页| 中文av字幕一区| 久久艳片www.17c.com| 亚洲视频碰碰| 美女啪啪无遮挡免费久久网站| 亚洲女性喷水在线观看一区| 欧美1级日本1级| 久久免费视频在线观看| 欧美三级乱人伦电影| 久久久久久成人| 国产精品国产一区二区| 欧美国产大片| 一区二区三区在线观看视频| 亚洲综合第一| 亚洲视频第一页| 免费成人网www| 久久综合99re88久久爱| 国产伦精品一区二区| 中文久久乱码一区二区| 99re亚洲国产精品| 男女视频一区二区| 欧美大胆人体视频| 国模大胆一区二区三区| 午夜精品久久久久久99热软件 | 欧美电影免费| 国产一区二区三区自拍| 亚洲午夜在线视频| 亚洲欧美国产高清va在线播| 欧美色区777第一页| 日韩亚洲国产欧美| 亚洲网友自拍| 欧美日韩国产欧| 亚洲精选国产| 亚洲少妇中出一区| 欧美色另类天堂2015| 亚洲乱码精品一二三四区日韩在线| 亚洲欧洲在线看| 欧美国产精品一区| 亚洲国产网站| 亚洲天堂成人在线观看| 欧美系列亚洲系列| 亚洲一区二区三区777| 亚洲欧美一区二区三区在线| 国产精品免费观看在线| 亚洲欧美日韩国产中文| 久久久av水蜜桃| 在线不卡欧美| 欧美黑人一区二区三区| 亚洲人被黑人高潮完整版| av成人免费在线| 国产精品h在线观看| 午夜国产不卡在线观看视频| 久久免费视频在线观看| 在线不卡欧美| 欧美日韩另类一区| 亚洲欧美日韩精品一区二区| 久久久五月婷婷| 亚洲国产91| 欧美日韩亚洲一区三区| 午夜视频一区二区| 欧美黄污视频| 欧美高清视频在线| 久久精品国产久精国产爱| 国产综合欧美在线看| 久久中文字幕一区二区三区| 亚洲韩国精品一区| 欧美一级片在线播放| 在线高清一区| 欧美丝袜一区二区| 欧美在线播放一区| 亚洲美女电影在线| 久久蜜桃资源一区二区老牛| 亚洲精品国产视频| 国产噜噜噜噜噜久久久久久久久| 欧美在线一级视频| 一区二区三区毛片| 欧美电影免费网站| 欧美一区二区在线免费观看| 亚洲欧洲日产国码二区| 国产欧亚日韩视频| 欧美日本韩国一区二区三区| 欧美一区二区三区在线视频 | 午夜日韩电影| 亚洲国产毛片完整版| 欧美在线一区二区| 在线一区欧美| 亚洲国产导航| 好吊视频一区二区三区四区| 欧美三级电影大全| 欧美www在线| 欧美一区二区三区视频免费| 亚洲另类在线一区| 亚洲电影一级黄| 久久婷婷色综合| 欧美专区在线播放| 亚洲男女毛片无遮挡| 夜夜嗨av一区二区三区四季av| 欲香欲色天天天综合和网| 国产女主播在线一区二区| 欧美区高清在线| 欧美大学生性色视频| 久久一区二区精品|