è¦ç´
12æ1æ¥ã®Update1ã§Visual C++ã«moduleã試é¨çã«å®è£ ããã¾ãã channel9.msdn.com
ãã®moduleã®ææ³ã¯ãããã
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4214.pdf
ã¨è¿ããã®ã«ãªã£ã¦ãã¾ãã
moduleã¨ã¯
javaã®package/importããC#ã®namesoace/usingã®ãããªãä»ã®é«ç´è¨èªã§ã¯ããã¥ã©ã¼ãªæ©è½ã§ããé¢é£ããã³ã³ãã¼ãã³ã群ãå ¬éç¯å²ã調æ´ãã¦å¤é¨ã¸å ¬éã§ããæ©è½ã¨ãã£ãã¨ããã§ãããããããã«ãããã©ã¤ãã©ãªãã¨ã®ååè¡çªãé²ãããå®è£ ãé®è½ãã¦ççµåã«ã§ããæ©æµãããã¾ãã
2015å¹´æç¹ã®C++ã«ã¯ã¢ã¸ã¥ã¼ã«æ©è½ã¯ããã¾ããããã£ã¨åå§çãªãCã®æ代ããåå¨ããããããincludeããã³ããæ©è½ã§èª¤éåãã¦ãã¾ããããã®æ¹æ³ã§ã¯includeãããããã®é åºã«ãã£ã¦æ¯ãèããå¤ããæããåå¨ããããã³ã³ãã¤ã«æéã®å¢å¤§ã®åå ã¨ãªã£ã¦ãã¾ããããããã£ããã¨ã«å¯¾å¦ããæå³ã§ããmoduleæ©è½ã¯å¿ é ã¨ããã¾ãã
使ãæ¹
æ¬å½ã«è©¦é¨çãªå®è£ ã§ãã¾ã Visual Studioä¸ã§å¿«é©ã«å©ç¨ã§ãããã¨ããã¬ãã«ã«ã¯éãã¦ã¾ãããmoduleã®è©³ããææ³ã¯
本の虫: 2014-10-pre-UrbanaのC++標準化委員会文書のレビュー: N4210-N4219
ãåç §ãã¦ä¸ãããã³ãã³ãããã³ããã使ãæ¹æ³ã¨ãVisual Studioã使ãæ¹æ³ãç´¹ä»ãã¾ãã
ã³ãã³ãããã³ããã使ã
cmdã§ãã§ããªãã¯ãªãã§ããããã¹ãéã£ã¦æ¥½ã«ä½¿ãããéçºè
ç¨ã³ãã³ãããã³ããforVS2015ãã使ãã¨è¯ãã§ããããVS2015ã¤ã³ã¹ãã¼ã«æã«ä¸ç·ã«å
¥ã£ã¦ããã®ã§æ¢ãã¦ã¿ã¦ãã ããã
ä»»æã®ãã©ã«ãã§ãmoduleã宣è¨ãã¯ã©ã¹ãé¢æ°ãªã©ãexportãããã¡ã¤ã«ãä½æãã¾ãããã®ãã¡ã¤ã«ã®æ¡å¼µåã¯.ixx
ã§ããå¿
è¦ãããã¾ããä»åã¯calc.ixx
ã¨ããååã§ä½æãã¾ããã
次ã«ä»¥ä¸ã®ããã«è¨è¿°ãã¾ãï¼
module calc; export { int add(int x, int y); int sub(int x, int y); } int add(int x, int y) { return x + y; } int sub(int x, int y) { return x - y; }
module calc;
ã§ããã®å®£è¨ä»¥ä¸ã®ã¯ã©ã¹ãé¢æ°ãªã©ããã®moduleã«æå±ãã¾ããexportãããã¯ã®ä¸ã«ãå¤é¨ã«å
¬éãããã¯ã©ã¹ãé¢æ°ã宣è¨ãã¾ããããã¯ã
module calc; export int add(int x, int y) { return x + y; } export int sub(int x, int y) { return x - y; }
ã®ããã«åå¥ã«æ¸ããã¨ãã§ãã¾ããããã¦ããã¡ã¤ã«ãä½æãããã©ã«ãã§
cl.exe /c /experimental:module calc.ixx
ã¨clãå®è¡ãã¾ããããã¨åããã©ã«ãã«calc.obj
ã¨calc.ifc
ã¨ãããã¡ã¤ã«ãä½æããã¾ãã
(èªåã®å®è¡çµæä¾)
C:\Users\takuya\dev\ModuleTest_>cl.exe /c /experimental:module calc.ixx Microsoft(R) C/C++ Optimizing Compiler Version 19.00.23506 for x86 Copyright (C) Microsoft Corporation. All rights reserved. Experimental features are provided as a preview of proposed language features, and we're eager to hear about bugs and suggestions for improvements. However, note that these experimental features are non-standard, provided as-is without support, and subject to breaking changes or removal without notice. See http://go.microsoft.com/fwlink/?LinkID=691081 for details. calc.ixx C:\Users\takuya\dev\ModuleTest_>dir ãã©ã¤ã C ã®ããªã¥ã¼ã ã©ãã«ãããã¾ããã ããªã¥ã¼ã ã·ãªã¢ã«çªå·ã¯ E24A-3B05 ã§ã C:\Users\takuya\dev\ModuleTest_ ã®ãã£ã¬ã¯ã㪠2015/12/02 06:38 <DIR> . 2015/12/02 06:38 <DIR> .. 2015/12/02 06:38 1,499 calc.ifc 2015/12/02 06:35 170 calc.ixx 2015/12/02 06:38 550 calc.obj 3 åã®ãã¡ã¤ã« 2,219 ãã¤ã 2 åã®ãã£ã¬ã¯ã㪠806,601,965,568 ãã¤ãã®ç©ºãé å C:\Users\takuya\dev\ModuleTest_>
calc.ixxã¨åããã©ã«ãã«main.cpp
ãä½æãã次ã®ããã«æ¸ãã¦ãã ããï¼
#include <iostream> import calc; int main() { std::cout << add(1, 2) << std::endl; std::cout << sub(1, 2) << std::endl; }
ãããããcalc.ixxã¨åãããã«
cl.exe /c /experimental:module main.cpp
ã¨å®è¡ãã¾ãããã¨ã¯objããªã³ã¯ããã°å®è¡ãã¡ã¤ã«ãã§ãã¾ãã
link *.obj
ä»åã¯calc.exeãä½æãããã¨æãã¾ããå®è¡ãã¦
3 -1
ã¨è¡¨ç¤ºããããæåã§ãï¼
Visual Studioã使ã
é©å®ãã½ãªã¥ã¼ã·ã§ã³ãããã¸ã§ã¯ããã¡ã¤ã«ãä½æãã¾ãã次ã«ã³ãã³ãããã³ããã使ãæ¹æ³ã¨åããã¡ã¤ã«ãããã¸ã§ã¯ãã«ä½æãã¦ããã®ã§ããã calc.ixxã¨ãããã¡ã¤ã«åã§ãã¡ã¤ã«ãä½æããã¨ããã¸ã§ã¯ãã®ã³ã³ãã¤ã«ãè¡ããã¡ã¤ã«ã«å«ã¾ããªãããã«ãªã£ã¦ãã¾ãã¾ããã¤ã¾ããobjãçæããããªã³ã¯ã¨ã©ã¼ã«ãªã£ã¦ãã¾ãã¾ãã
ixxãã¡ã¤ã«ãã³ã³ãã¤ã«ã«è¿½å ããã«ã¯ãcalc.ixxãå³ã¯ãªãã¯ããããããã£ãéãã¾ããæ§æããã㣠> å
¨è¬
ãããé
ç®ã®ç¨®é¡
ãC/C++ ã³ã³ãã¤ã©
ãé¸æãã¾ããããã§calc.ixxãã³ã³ãã¤ã«ãããããã«ãªãã¾ããã(srz_zumixãããææãããã¨ããããã¾ã)
calc.ixxã¨main.cppã®ä¸èº«ã¯ã³ãã³ãããã³ããã使ãæ¹æ³ã¨åãã«ãªãã¾ãã®ã§ãã¡ãã®ãµã³ãã«ã³ã¼ããåèã«ãã¦ãã ããã
ããã¸ã§ã¯ãã®ããããã£ãéããæ§æãããã㣠> C/C++ > ã³ãã³ãã©ã¤ã³
ã«/experimental:module
ã追è¨ãã¾ãã
é©ç¨(A)
ãæ¼ãã¦éãã¾ãã
次ã«ixxãã¡ã¤ã«ãããããã½ãªã¥ã¼ã·ã§ã³ã¨ã¯ã¹ããã¼ã©ã¼ä¸ããå³ã¯ãªãã¯ããããããã£ãé¸æãã¾ããæ§æãããã㣠> C/C++ > ã³ãã³ãã©ã¤ã³
ã«/c
ã追è¨ãã¾ãã
é©ç¨(A)
ãæ¼ãã¦éãã¾ãã
å¾ã¯æ®æ®µVisual Stuidoä¸ã§éçºãè¡ãããã«Ctrl + F5ãªããCtrl + Shift + BãªããF5ãªãæ¼ãã¦ãã«ããæåãå®è¡ã§ããã¯ãã§ããä¸æããããªãå ´åã¯ããã¸ã§ã¯ãã®ãªãã«ãã試ãã¦ã¿ã¦ãã ãããixxãã¡ã¤ã«ãæ´æ°ãããã³ã«ãªãã«ããå¿ è¦ãªç¹ã注æã§ãã
ã¾ã¨ã
ãã®è¨äºã§è§¦ãããã¨ãã¾ã¨ãã¾ãã
- Visual Studio 2015ã§C++ã«moduleã試é¨çã«å®è£ ããã
- moduleã¨ã¯ä½ã
- ã¾ã IDEã®ãµãã¼ãã¯å¼±ã
- å®éã«moduleãå«ãã ã³ã¼ãããã«ãããæ¹æ³(CUIã¨GUIãããã)
ç§ãã¾ã 試ããããã¨ããè²ã ãã(templateã¯ã§ããã®ããexportã¯ãã¹ãã§ããã®ã(=com.hoge.util.func(1, 2)ã®ãããªãã¨ãã§ããã®ã)ç)ã®ã§ãããã£ã¦éãã§ã¿ããã¨æãã¾ãã