ãµã¤ãã¦ãºã»ã©ãã®å æã§ãã
ä»å¹´ã®1æãããEffective Modern C++ãï¼Scott Meyersï¼ã®èªæ¸ä¼ã社å¤ã®äººãå«ãã¦æ1åã®ãã¼ã¹ã§å§ããå ææ«ã«ç¡äºæå¾ã¾ã§çµããã¾ããã ãã®ææ³ããã£ã¨ç´¹ä»ãããã¾ãã
ãEffective Modern C++ãï¼ä»¥ä¸EMCã¨ç¥ï¼ã¯C++11/C++14ã§è¿½å ãããæ§ã ãªæ°ããæ©è½ã«ã¤ãã¦ç´¹ä»ããæ¬ã§ãã å¾ã£ã¦ãC++ã®å ¨ãã®åå¿è ãèªãã«ã¯å°ã é£ããã¨æãã¾ãã以åã®C++ã«ããç¨åº¦ç¿çãã人ããæ°æ©è½ã®æ³¨æç¹ãåå¼·ãããã¨ããã¨ãã«ä½¿ãã¨ããã§ãããã æ¬ã«ã¯éè¦ãªééããããã¤ãææããã¦ãã¾ãã®ã§æ£èª¤è¡¨ã®ç¢ºèªã¯ãã¦ããã¾ãããã
ãªããã®9æã«ã¯æ¥æ¬èªçï¼åä½æ²»é訳ï¼ãç»å ´ãã¦ãã¾ãããã¡ãã¯7ææç¹ã§åæ¸ã«è¦ã¤ãã£ã¦ããæ£èª¤è¡¨ãåæ ããã¦ãã¦ããããã§ããã
C++11ã§ã¯autoã®åæ¨è«ãtypedefããé«æ©è½ãªusingãé«æ©è½ãªenumãä¸è¬åãããå®æ°ãæ±ãconstexprãã¹ãã¼ããã¤ã³ã¿ãmoveãã©ã ãå¼ãthreadãªã©å¤æ°ã®æ©è½ã追å ããã¦ãã¾ãã ããã§ã¯è©³ç´°ã«ã¯ãµãã¾ããã Wikipediaã®C++11ãStandard C++ãããã©ããè¦æ ¼æ¸ã®ãã©ãããªã©ãåç §ãã¦ãã ããã
EMCãç¶²ç¾ çã«è§£èª¬ãã¦ããã®ã§ã¯ãªããããã®ãã¡ã®ä¸é¨ãéç¹çã«è§£èª¬ãã¦ãã¾ãã EMCåå¼·ä¼ã§ã¿ãªãããçºè¡¨ãããè³æã¯GitHubã®emcjpåå¼·ä¼ã«ç½®ãã¦ãã¾ãã
ããã§ã¯å人çã«é¢ç½ãã£ããããã¯ãä¸å¿ã«ãã£ããã¨ç´¹ä»ãã¾ãããã
åæ¨è«ï¼1ï½2ç« ï¼
èªã¿å§ããã¨ããããªããã³ãã¬ã¼ãã®åæ¨è«ã¨ããé«åº¦ãªè©±ããå§ã¾ã£ã¦å°ã é©ããã®ã§ãããautoãã¼ã¯ã¼ããæ£ãã使ãã«ã¯å¿ é ã®äºé ãªã®ã§ããã¾ã¾ã§ãªãã¨ãªãç解ãã¦ããã¨ãã人ã¯èªãã§ããã¨ããã§ãããã
www.slideshare.net
åæ¨è«1ç« ã¯ä¸è¨æ¥æ¬èªçã®é¢é£ãã¡ã¤ã«ããç¡æã§èªãã¾ãã ãªããèè ããã®æ¬ã§ä½¿ç¨ãã¦ããç¬èªç¨èªuniversal referenceã¯C++ã®è¦æ ¼ã¨ãã¦ã¯forwarding referenceã¨ããååã§ä½¿ããå§ãã¦ãã¾ãï¼cf. N4164ï¼ã
åå¿è ãautoã使ã£ãã¨ãã«é¥ããããç¹ãä¸ã¤ã ãæããã¨ã
std::vector<std::string> vs;
ã®å ¨è¦ç´ ãåç §ã ããããï¼æ¹å¤ã¯ããªãï¼ã¨ãã«
for (auto s : vs) { ä¸èº«ãåç §ããã ã }
ã¨ããã³ã¼ããæ¸ãã¦äºæ³å¤ã®ããã©ã¼ãã³ã¹ä½ä¸ã«æ©ã¾ãªãããã«ãã¦ãã ããã
ããã§ã¯
const auto& sã«ããå¿ è¦ãããã¾ãã ããããªãã¨ã«ã¼ãã®ä¸ã§æ¯åæååã®ã³ãã¼ãçºçããããã§ãã
nullptr, using, enum, override, noexceptï¼3ç« ï¼
ãããã¯æ°ãã追å ããããããã便å©ã«ãªã£ãæ©è½ã®ä¸ã§ã¯ããã»ã©è½ã¨ãç©´ã¯ããã¾ãããããããã®è©²å½åæãåç §ãã¦ããã ããã使ããã¨æãã¾ãã
ã¹ãã¼ããã¤ã³ã¿ï¼4ç« ï¼
ã¾ãã¯ãã¾ã¾ã§ã®auto_ptrã®ä½¿ç¨ãæ¢ãã¦unique_ptrã«ç§»è¡ãããã¨ã ãè¦ããã¨ããã§ãããã
www.slideshare.net
shared_ptrã¯ä¾¿å©ã ã¨ãã£ã¦ããã¿ã«ä½¿ãããã§ããã ãããã使ããªãã§ãã¡ã¢ãªç®¡çãã§ãããèããæ¹ãããã¨æãã¾ãã
å³è¾ºå¤åç §ãmove, perfect forwardingï¼5ç« ï¼
ãããã®æ¦å¿µã¯ãªããªãé£ããã§ãã æ¨æºã©ã¤ãã©ãªã使ãã ããªãèªç¶ã«ãã®æ©æµãåãããã¨ãå¤ãã¨æãã¾ãããèªåã§ä½ãã©ã¤ãã©ãªã対å¿ãããã¨ãã¯ãã®ç« ããã¡ãã¨ç解ããå¿ è¦ãããã¾ãã Item 17ã§ç´¹ä»ãããæé»ã«çæãããã¡ã³ãé¢æ°ã«ã¤ãã¦ãåããã¦è¦ã¦ããã¾ãããã
www.slideshare.net
ã¾ãã³ãã¼ã¨moveã¨ã©ã使ãåããã¹ããã«ã¤ãã¦ã¯Item 41ã§ç´¹ä»ãããé¢æ°ã®å¼æ°ã®æ±ãã«é¢ããèå¯ããã£ããèªãã¨ããã§ãããã
ã©ã ãå¼ï¼6ç« ï¼
è¤éãªãã¨ã¯ãããSTLã®æ¯è¼é¢æ°ããã®å ´ã§å ¥ãããªã©ã¡ãã£ã¨ãããã¨ã®ã¿ã«ä½¿ãã¨ããæ¹éãã¨ãã°ãè½ã¨ãç©´ã«ã¯ã¾ããã¨ãªããã®æ©æµãåååããããã¨æãã¾ãã
www.slideshare.net
並è¡APIï¼7ç« ï¼
å人çã«ã¯æå¤ã ã£ãã®ã§ããããã®æ¬ã§ã¯std::threadãããstd::asyncã使ã£ãææ³ãæ¨ãã¦ãã¾ããã threadã使ãããã¯æ°è»½ãªã®ã§ãããããã§ããããè½ã¨ãç©´ãããã®ã§ããã©ã«ãã®ä»æ§ããã¡ãã¨ç解ããå¿ è¦ãããã¾ãã
www.slideshare.net
std::threadã«é¢ãã¦ã¯ãjoinããã«ç ´æ£ãããªãã¨ãããã¨ãå¿ãã¦ã¯ããã¾ããã
ããä¸ã²ããï¼8ç« ï¼
std::stringãä¾ã«ã¤ã³ã¹ã¿ã³ã¹ã®çæãã³ãã¼ãmoveã«ã¤ãã¦é常ã«ç²¾å¯ãªè°è«ãå±éãã¾ãã ãã¨ãã°std::stringãå¼æ°ã«ã¨ãã¨ããåç´ãªã¡ã½ããã®è¨è¨ã«ã¤ãã¦ããæååãªãã©ã«ã渡ããã¨ããæ¢ã«å¤ãè¨å®ããã¦ããã¨ããä¸åº¦é·ãæååãè¨å®ãããã¨ããªã©æ§ã ãªç¶æ³ã§ã®ã³ã¹ããæ¯è¼ãã¾ãã C++ã®é¢åãªã¨ããã§ããããèªç±åº¦ã®é«ãã示ãç« ã§ãããã¨æãã¾ãã
www.slideshare.net
ãããã«
ä¸è¨ãªã³ã¯ããè³æã¯ä¸é¨ã§ããemcjpåå¼·ä¼ã«ã¯ä»ã®Itemã®è³æãã¢ããããã¦ãã¾ããåèã«ãã¦ãã ããã
ã¾ãé¢ç½ãããªæ¬ããããã¯ãè¦ã¤ããã°ããããåå¼·ä¼ãéãããã¨æãã¾ãã
æå¾ã«ãªãã¾ãããå¹³æ¥å¤ã®éå¬ãªãããåå ãã¦çºè¡¨ããããæ´»çºãªè°è«ããã¦ãã ãã£ãã¿ãªãã¾ã«æè¬ãã¾ãã