ãC ++ 11ã¯æ°ããèšèªã®ããã«æããŸããby Bjarne Stroustrup
ãç§ãã¡ã¯ãã¹ãŠC ++ 11ãåŠãã§ããŸããããŒããµãã¿ãŒ
ãç§ãã¡ã¯å°çäžã®ãã¹ãŠã®æ¬ãç Žããå°çäžã®ãã¹ãŠã®ããã°ã©ããŒãç ŽããŸãããããŒãã»ãµãã¿ãŒ
éäŒã®æšæ¶ã§ãããŒããµãã¿ãŒã¯Cèšèªã®äœæè ã§ãããUNIXãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã®äž»èŠãªéçºè ã§ããããã¹ãªãããŒã«äŒè°ãæ§ããŸããã
ããã¯C ++ã³ãã¥ããã£ã«ãšã£ãŠéåžžã«éèŠãªã€ãã³ãã§ãããC ++ã®äžçã§äŒèª¬ãšãªã£ã人ã ã質åããå€ãã®ç¹ã§ãã®éçºã決å®ããŸããã ã¬ããŒãã¯éââåžžã«èå³æ·±ããã®ã§ãããç§ã¯èªåèªèº«ã®ããã«å€ãã®æ°ãããã®ãäœããŸããã 次ã¯ããã¹ãŠã®ã¬ããŒããšè³ªçå¿çã»ãã·ã§ã³ã®æŠèŠã§ãã
ã¹ããŒã«ãŒã®ãªã¹ãïŒ
- Bjarne Stroustrup ïŒC ++ã®äœæè ïŒ
- ããŒããµãã¿ãŒ ïŒC ++æšæºå§å¡äŒå§å¡é·ããã€ã¯ããœããã®ãœãããŠã§ã¢ã¢ãŒããã¯ãïŒ
- Andrei Alexandrescu ïŒDããã°ã©ãã³ã°èšèªã®äœè ã®1人ã§ããFacebookã®C ++ãã³ãã¬ãŒãããã³ããã°ã³ã³ãã¥ãŒãã£ã³ã°ãã¹ã¿ãŒïŒ
- Chandler Carruth ïŒLLVM / Googleã®Clangéçºè ïŒ
- Stephan T. Lavavej ïŒVisual C ++ LibrariesããŒã ã®STLãã¹ã¿ãŒïŒ
- Hans Boehm ïŒHP Labsã®åæ£ã³ã³ãã¥ãŒãã£ã³ã°ãšãã¹ããŒãïŒ
- ã¢ã³ããªã¥ãŒã»ãµããã³ ïŒãããµã¹AïŒM倧åŠã®C ++ã©ã€ãã©ãªèšèšãšãã¹ããŒãããã³ISOå§å¡äŒã¡ã³ããŒïŒ
èšèªã®çŸåšã®ç¶æ ã«èå³ããã人ã¯ã次ã®3ã€ã®å€èŠ³ãèŠãããšããå§ãããŸãã
- ããŒããµãã¿ãŒïŒC ++ 11ãVC ++ 11 and BeyondïŒ ãªã³ã¯ ïŒ
- Bjarne StroustrupïŒC ++ 11ã¹ã¿ã€ã«ïŒ ãªã³ã¯ ïŒ
- Stephan T. LavavejïŒSTL11-Magic && SecretsïŒ ãªã³ã¯ ïŒ
ä»ã®ã¬ããŒãã泚ç®ã«å€ããŸãããããçããããã¯ïŒäžŠåããã°ã©ãã³ã°ãClangã³ã³ãã€ã©ããã³ãã¬ãŒããæŠå¿µïŒã«å°å¿µããŠããŸãã ã€ãã³ãã¯ã質çå¿çã®2ã€ã®ã»ãã·ã§ã³ã§é£ŸãããŸããã äŒè°ã®ãã¹ãŠã®ãããªãšã¹ã©ã€ãã¯ã ãã£ã³ãã«9ã§ããŠã³ããŒãããŠãªã³ã©ã€ã³ã§èŠèŽã§ããŸãã
1æ¥ç®-C ++ 11ä»æ¥-2012幎2æ2æ¥
Bjarne StroustrupïŒC ++ 11ã¹ã¿ã€ã«
Bjarneã¯ãåªããããã°ã©ãã³ã°ã¹ã¿ã€ã«ã§ããC ++ã®é·æã«ã€ããŠèªããå€ãã®äŸã瀺ããŸãã ãã¯ãã«ãšãªã¹ãã®ããã©ãŒãã³ã¹ã®æ¯èŒã¯èå³æ·±ããã®ã§ããçµæã¯äºæ³å€ã®ããã«æãããæèã®ç³§ãšãªããŸãã
Hans BoehmïŒC ++ 11ã®ã¹ã¬ãããšã·ã§ã¢å€æ°
æåŸã«ãC ++ã§ã¯ããã«ãã¹ã¬ãããèšèªæšæºã«ãªããŸããã ã¹ã¬ããã®èšèšã¯ãããç¥ãããŠããboost.threadã©ã€ãã©ãªã®èšèšã«ã»ãŒåŸã£ãŠããŸãã éåæåŒã³åºãã®éåæ/å°æ¥ã®ãµããŒãã«ã€ããŠèšåããŸããã ãã¥ãŒããã¯ã¹/ããã¯ã®äœ¿çšäŸããããŸãã
ãã¬ãŒã³ããŒã·ã§ã³ã®äž»èŠéšåã¯ãããŒã¿ã¬ãŒã¹å°çšã§ãã C ++ããã°ã©ã ã®å 容ãšãããŒã¿ã¬ãŒã¹ãçºçããå Žåã«äºæãããå 容ã®æ£ç¢ºãªå®çŸ©ã瀺ãããŠããŸãã ç»å Žããã¢ãããã¯ã¿ã€ãã«ã€ããŠå€ãã®ããšãèšãããŠããŸãããæ¯èŒã¯Javaã®volatileïŒãšæ¯èŒãããŸãã
ã¹ããã¡ã³ã»Tã»ã©ãŽã¡ãŽã§ãŒãžïŒSTL11-Magic && Secrets
STLã¯ãæšæºC ++ã©ã€ãã©ãªã®å€ãã®é©æ°ã«ã€ããŠèªã£ãŠããŸãã
- åç
§ã«ãŠã³ã¿ãŒä»ãã®ãã€ã³ã¿ãŒã ãã¯ããã¯ãã¿ã€ãæ¶å»ãã make_sharedã䜿çšããŠshared_ptrãäœæããæ¹ãè¯ãçç±
auto sp1 = make_shared<T>( args ); // 1 allocation, 24 bytes overhead shared_ptr<T> sp2( new T( args ) ); // 2 allocations, 40 bytes overhead
- é
眮ïŒã³ã³ããå
ã«ãªããžã§ã¯ããçŽæ¥æ§ç¯ããŸã
v.emplace_back("Carmichael", 3 * 11 * 17); // more efficient, easier to type v.push_back( make_pair("Carmichael", 3 * 11 * 17) );
- æ°ããæšæºãstd ::ãã¢ãã»ãŒãç Žã£ããæ¹æ³ããŸãã¯NULLã§ã¯ãªãnullptrã䜿çšãã䟡å€ãããçç±
pair<X*, double> p1(NULL, 3.14); // - , pair<X*, double> p2(nullptr, 3.14);
- Futures / asyncããããŠãªãéããªããžã§ã¯ããåç §ã§ã¯ãªãå€ã§æž¡ãã»ããããã®ã
- ç¯å²ããŒã¹ã®forã¯VC11ã«è¡šç€ºããããã§ã«VC11 Betaã«å«ãŸããŠããŸãã å®è£ æ¹æ³ãããã³autoãšçµã¿åãããŠäœ¿çšââããæ¹ãè¯ãçç±
- autoïŒèšè¿°ããããã ãã§ãªããããå¹ççãªã³ãŒããåŸãããå ŽåããããŸã
map<string, int> m; // ? for (const auto& p1 : m) { ⊠} for (const pair<string, int>& p2 : m) { ⊠}
Andrei AlexandrescuïŒå¯å€é·ãã³ãã¬ãŒãã¯Funadicã§ã
ã...çµå±ã®ãšããã圌ã¯èª°ã§ããã¹ãããšããããšã¯çŽ æŽãããããšããã-æããããã¯ãããããçŽ æŽããããã
ãã³ãã¬ãŒãã¡ã¿ããã°ã©ãã³ã°ã®ç¬¬äžäººè ã®ãã¬ãŒã³ããŒã·ã§ã³ã§ã¯ãVariadic Templatesã«ã€ããŠè©±ããŠããŸããå¯å€æ°ã®ãã©ã¡ãŒã¿ãŒã§ãã©ã¡ãŒã¿ãŒåããããã³ãã¬ãŒãã¯ã©ã¹/é¢æ°ãäœæã§ããC ++ 11æšæºã®æ°æ©èœã§ãã ããšãã°ãCããprintf / scanfé¢æ°ã®ã¿ã€ãã»ãŒããªã¢ããã°ãèšè¿°ã§ããããã«ãªããŸãããã»ãšãã©ã®C ++ããã°ã©ããŒã¯ãVariadicãã³ãã¬ãŒãã䜿çšããŠèªåã§äœããèšè¿°ããå¿ èŠã¯ã»ãšãã©ãããŸãããããã®æ©èœã¯ã©ã€ãã©ãªäœæè ã«ãšã£ãŠéåžžã«éèŠã§ãã ãã¬ãŒã³ããŒã·ã§ã³ã¯ã䜿çšãããŠããæ§æãèŠãŠãVariadicãã³ãã¬ãŒãã®äœ¿çšæ¹æ³ãç解ããã人ã«ãšã£ãŠèå³æ·±ããã®ã«ãªããŸãã
ããã©ãŒãã³ã¹ã«ã¯3ã€ã®éšåãå«ãŸããŸãã
- Variadicãã³ãã¬ãŒããäœã§ãããããªãå¿
èŠãªã®ããæ§æã説æãããæž¡ãããæåã®åŒæ°ã次ã®ãããããšçãããã©ããã決å®ããé¢æ°ã®äŸã瀺ãããŸã
isOneOf(1, 1); // => true isOneOf(1, 2, 6); // => false isOneOf(1, 3.5, 4, 1, 2); // => true
- Cããã®printfé¢æ°ã®åçŽãªã¢ããªã³ãå®è£
ãããæž¡ãããã¿ã€ããšãã©ãŒãããæååã®å¯Ÿå¿ããã§ãã¯ããŸãã
safe_printf( â%d %fâ, 12.1, 1.1 ); // => throws invalid format exception safe_printf( â%dâ, 1, 2, 3, 4, 5 ); // => throws too few format specifiers exception safe_printf( â%d %fâ, 11, 12.1 ); // => ok, redirects to printf(âŠ)
- std :: tupleã¯ã©ã¹ã®å¯èœãªå®è£
ã瀺ãããŠããŸãïŒC ++ 11æšæºããïŒ
tuple<int, string, double> t; get<0>(t) = 42; assert(get<0>(t) == 42); get<0>(t) = âthis will not compileâ; // => compilation error get<1>(t) = "forty-two"; get<2>(t) = 0.42;
ããã«ïŒãã€ãã£ãã§ããããšã®éèŠæ§ïŒBjarneãAndreiãHerbãHansãStephanïŒ
質åã«çããã»ãã·ã§ã³ïŒ
- C ++ãçãã§ããã°ã質åã¯äœã§ããïŒ
- C ++èšèªã®ã¿ãŒã²ãããçµã£ãããã¢ãŒã·ã§ã³ã«é¢äžããŠãã人ã¯ããŸããïŒ
- è¿ãå°æ¥ãã¢ãžã¥ãŒã«ãµããŒãã¯C ++ã«ç»å ŽããŸããïŒ
- Variadic Templatesã䜿çšããŠã³ãŒããäœæãããµããŒãããã®ã¯èª°ã§ããïŒ
- ã¿ã¹ã¯ããŒã¹ã®äžŠååŠçïŒPPLãªã©ïŒãGPGPUã䜿çšããã³ã³ãã¥ãŒãã£ã³ã°ãã³ã«ãã³ããµããŒãããæšæºããŒã«ã«å«ããèŠèŸŒã¿ã¯ãããŸããïŒ
- C ++ã®ã¬ããŒãžã³ã¬ã¯ã·ã§ã³ã®èŠéãã¯ã©ãã§ããïŒ
- ãã€ããªäºææ§ã¯C ++ã§è¡šç€ºãããŸããïŒ
- ããŒããªã¢ã«ã¿ã€ã ã·ã¹ãã ã®ããã°ã©ãã³ã°ãã«ãŒãã«éçºãžã®C ++ã®é©çšæ§
- ...
ããã€ãã®èå³æ·±ãåŒçšïŒ
ãããããã¬ããŒãžã³ã¬ã¯ã·ã§ã³ã¯ä»ã®å€ãã®èšèªã»ã©C ++ã«ãšã£ãŠéèŠã§ã¯ãªããšæããŸãã ããã»ã©å€ãã®ãŽããçæããããšã¯ãããŸãããBjarne Stroustrup
ã...ç§ãC ++ã®ãã¬ãŒãã³ã°ãšæ å ±ã«ã€ããŠæãããåãåãã¡ãŒã«ã®ã«ããŽãªã¯ãJavaãšCïŒéçºè åãã®ææ°ã®C ++ 11ã®äœ¿çšæ¹æ³ã«é¢ããåªãããã¯ã€ãããŒããŒãèŠã€ããããå Žæã§ãããšèšã£ãŠãã人ããã§ãã
2æ¥ç®-C ++ 11ä»æ¥ãšææ¥-2012幎2æ3æ¥
ããŒããµãã¿ãŒïŒC ++ 11ãVC ++ 11以é
Sutterã¯ãVC11ã®æ¬¡ã®ããŒãžã§ã³ã§C ++ 11æšæºã©ã€ãã©ãªãå®å šã«ãµããŒãããããšãçŽæããŸãããŸããïŒåã°ããããšã«ïŒä»æäºå®ã®ããŒã¿ããŒãžã§ã³ã§ã¯ãç¯å²æå®ããã³æçµ/ãªãŒããŒã©ã€ãã®ãµããŒãã衚瀺ãããŸãã VC11ã®ãªãªãŒã¹åŸããã«ããã€ãã®ã垯åå€ããªãªãŒã¹ïŒVisual StudioãªãªãŒã¹ã«é¢é£ä»ããããŠããªãïŒããªãªãŒã¹ããæ°ããæšæºã®ãµããŒããåŸã ã«æ¹åããŠããäºå®ã§ãïŒåæåãªã¹ãããã³ãã¬ãŒããšã€ãªã¢ã¹ãå¯å€ãã³ãã¬ãŒããconstexprãnoexceptã= default / deleteã...ã¯ã調æ»ã«åå ããæ©äŒãæ°ããæšæºã®ã©ã®æ©èœãæãéèŠã§ãããã§ããã ãæ©ããããèŠãŠã¿ããïŒ bit.ly/mscpp11 ã
2çªç®ã®éšåã¯ãC ++ã§ã®ããã°ã©ãã³ã°ã®æ°ããã¹ã¿ã€ã«ãã€ãã£ãªã ãããã³æšå¥šãããæ¹æ³ã«å°å¿µããŸãã Sutterã¯ãC ++ã®ãã¹ãŠã®æ¬ã¯æšæºã®ãªãªãŒã¹ã§æ代é ãã«ãªããæ¬ã®åäŸã¯æ°ããã¹ã¿ã€ã«ã§æžãçŽãããšãã§ããããããããã¹ãã ãšäž»åŒµããŠããŸãïŒå°çäžã®ãã¹ãŠã®æ¬ãå£ããå°çäžã®ãã¹ãŠã®ããã°ã©ããå£ããŸããã C ++ 11ã«é¢ããæ¬ãå°ãªããšã1ã€æ¢ã«ååšããŠããŸãïŒ bit.ly/meyers11 ã C ++ã«é¢ããä»ã®æåãªæ¬ã®æŽæ°äºå®æ¥ïŒ
- C ++ãã©ã€ããŒïŒMooïŒ-2012幎8æ
- C ++ããã°ã©ãã³ã°èšèªïŒStroustrupïŒ-2012幎åŸå
- ããã°ã©ãã³ã°ïŒC ++ïŒStroustrupïŒã䜿çšããååãšå®è·µ-2013幎åŸå
- å®å¹C ++ïŒãã€ã€ãŒãºïŒ-2013-2014
- C ++ã³ãŒãã£ã³ã°æšæºïŒSutterãAlexandrescuïŒ-2015
3çªç®ã®éšåã§ã¯ãC ++æšæºã®å¯èœãªéçºèšç»ã«ã€ããŠèª¬æããŸãã 圌ã®æèŠã§ã¯ãã¹ã¿ã€ã«ã®ãã®ãããªæ¥é²çãªå€æŽãããã³C ++ 11ã®ãããªã€ãã£ãªã ã¯ãè¿ãå°æ¥æãŸãããããŸããã ã¹ããŒãã®æåŸã«ãçŽç« ã¯C ++ã®æã匱ãåŽé¢ãå¹æçã«èª¬æããç¶æ³ãä¿®æ£ããããã«äœãèšç»ããŠããããäŒããŸããã
Chandler CarruthïŒClang-ããŒãã£ãŒã®ããªãªã³ã¢ã³ããŒãºããC ++ãå®ã
Clangéçºè ã¯ãã©ã€ãgccã§å¥ã®C ++ã³ã³ãã€ã©ãèšè¿°ããå¿ èŠãããçç±ã«ã€ããŠèª¬æããŸãã
- æªããšã©ãŒã¡ãã»ãŒãž
- ã³ã³ãã€ã«é床ãé ã
- gccã®æè¡çç¹åŸŽãã³ãŒãåæããŒã«ã®æ§ç¯ã«ã¯é©ããªã
- GCCã®æ¿æ²»çå¶éã«ãããã³ãŒãåæããŒã«ã®æ§ç¯ã«ã¯é©ããªã
ææ°ããŒãžã§ã³ã¯ãC ++ 98æšæºãããã³éšåçã«C ++ 11ãå®å šã«ãµããŒãããŠããŸãã LinuxãMacã§åäœããŸãã éçºè ã®äžã«ã¯ååãªWindowséçºè ãããªããããWindowsã®ãµããŒãã¯ãããŸããã
åé¡ã®ããC ++ã³ãŒãã®å€ãã®äŸãšãã³ã³ãã€ã©ã«ãã£ãŠçæããããšã©ãŒã¡ãã»ãŒãžãšèŠåã èå³æ·±ãéçã³ãŒãã¢ãã©ã€ã¶ãŒãå€æããããã«èŠããŸãããå®è¡æã®åäœãåæããæ©äŒããããŸãã ã³ã³ãã€ã©ã«åºã¥ããŠãC ++ã³ãŒãããªãã¡ã¯ã¿ãªã³ã°ããã³åæããããã®éåžžã«èå³æ·±ãããŒã«ãéçºãããŠããŸãã ããšãã°ã äžèŠãªincludeãåé€ããããŒã« ã
ã¢ã³ãã¬ã€ã»ã¢ã¬ã¯ãµã³ãã¬ã¹ã¯ïŒãã³ããŒããã£ããéç
Dèšèªã§èšŒæãããŠããstatic_ifæ§æãèšèªã®æšæºã«è¿œå ããææ¡ã«ã€ããŠè©±ããŠããã®ã§ãä»ã§ã¯éããªãã§ã¯èŠãããªããã³ãã¬ãŒãã³ãŒããå€§å¹ ã«ç°¡çŽ åã§ããŸãã ãã®äœ¿çšæ¹æ³ã¯æ¬¡ã®ãšããã§ãã
// It â forward iterator template <class It> It rotate(It b, It m, It e) if (is_forward_iterator<It>::value) {...} // WithParent enum class WithParent { no, yes }; template <class T, WithParent wp> class Tree { class Node { ... }; static if (wp == WithParent::yes) { Node * parent_; } Node * left_, * right_; T payload_; }; Tree<string, WithParent::yes> dictionary;
Bjarne StroustrupãšAndrew SuttonïŒC ++ã®ã³ã³ã»ãããã¶ã€ã³
ã³ã³ã»ããã¯ãC ++ 11èšèªæšæºã«å«ãŸããŠããªãé·æã«ãããæ©èœã§ãããæ¡çšãå€§å¹ ã«é ããŸããã Straustrupã¯èšèªã®æŠå¿µãã©ã®ããã«ç解ããŠããããèªããSuttonã¯æè¡çãªè©³çŽ°ã«ã€ããŠèª¬æããŸãã ç§ãç解ããŠããããã«ãèšèªã«æŠå¿µãè¿œå ããããšããèŠæããŸã ãããææ¡ã¯æšæºåå§å¡äŒã«æåºãããŸãã ææ¡ã¯ããªãªãžãã«ãšæ¯èŒããŠç°¡çŽ åã®æ¹åã«çå£ã«äœãçŽãããŸããã ããã¯æŠå¿µã䜿çšããã³ãŒãã®ããã«èŠãããããããŸããïŒ
template<InputIterator I> DistanceType<I> distance(I first, I last); // template<RandomAccessIterator I> DistanceType<I> distance(I first, I last); // , random-access template<Sortable Iter> void sort(Iter first, Iter last);
ããã«ïŒäœã§ãèããŠãã ããïŒ ïŒãã¹ãŠã®ã¹ããŒã«ãŒïŒ
QïŒAã»ãã·ã§ã³ã å€ãã®ãããã¯ãã«ããŒãããŠããŸãïŒ
- C ++ãžã®æ¡çš
- constexpr
- shared_ptr
- åå°
- C ++ã®æ¬¡ã®æšæºã®èšç»
- ã¢ãžã¥ãŒã«
- å€çžã©ã ã
- ããŒã¿ãã«ã³ãŒããæžã
- ã³ã³ãã€ã©ãã³ããŒ
- ãã³ãã¬ãŒãã®ãšã¯ã¹ããŒã
- ã³ã³ã»ãã
- 䞊è¡æ§
- ãã«ãæé
- C ++æ§æ
- ãªãã¡ã¯ã¿ãªã³ã°ããŒã«
constexprã®è°è«ããïŒ
Chandler Carruth ïŒ...ãããããŸã çµãã£ãŠããŸããã ããã¯é£ããã å¯å€é·ãã³ãã¬ãŒããããé£ãããå®éã«ã¯ã©ã ããããé£ãããšæããŸãã C ++ 11å šäœã«æ©èœãæ£ããå®è£ ããããšã¯æãå°é£ãªäœæ¥ã®1ã€ã§ãã
Bjarne Stroustrup ïŒããã¯ãããã®æ©èœã®1ã€ã§ãããæšæºåäžã«ææ¡è ãšåæå®è£ è ã®æ»äœãè¶ ããŠããè€éã«ãªã£ãããšã«æ³šæããã®ã¯èå³æ·±ãããšã§ãã
äŒè°ã®äž»å¬è ãšåå è ã«æè¬ããŸã!!!