2006/08/19

ConceptGCC

今天才偶然發現,我從來沒看過 WG21 六月的 mailing list 全部內容,都只看到其中的 N2011 "State of C++ Evolution" XD。目前正在讀 N2042 "Concepts" by D. Gregor & B. Stroustrup,裡面提到一個實作品 ConceptGCC ─ 實作品耶!迫不及待立刻下載試用,網站上剛好提供了 Mac OS X 10.4 PPC 的 binary 檔案,省下不少麻煩。ConceptGCC 還只是 alpha version,最顯而易見的缺陷是:慢到爆炸 XD。第一次編譯時,我還以為餵檔失敗,看著 manual 的一句 "It provides the same behavior as GCC's g++ compiler driver" 百思不得其解 XD。

我寫了這樣的程式碼,觀察 concept system 面對錯誤的反應:

#include <algorithm>
#include <iterator>
#include <iostream>

using namespace std;

int main() {
  copy(0, 5, ostream_iterator<int>(cout, " "));
}

ConceptGCC 給我的錯誤訊息是:

test.cpp: In function 'int main()':
test.cpp:8: error: no matching function for call to 'copy(int, int, std::ostream
_iterator<int, char, std::char_traits<char> >)'
/opt/conceptgcc-4.1.1-alpha-3/lib/gcc/powerpc-apple-darwin8.6.0/4.1.1/../../../.
./include/c++/4.1.1/bits/stl_algobase.h:405: note: candidates are: _OutputIterat
or std::copy(_InputIterator, _InputIterator, _OutputIterator) [with _InputIterat
or = int, _OutputIterator = std::ostream_iterator<int, char, std::char_traits<ch
ar> >] <where clause>
test.cpp:8: note:   no concept map for requirement 'std::InputIterator<int>'
test.cpp:8: error: invalid use of undefined type 'concept std::IteratorAssociate
dTypes<int>'
/opt/conceptgcc-4.1.1-alpha-3/lib/gcc/powerpc-apple-darwin8.6.0/4.1.1/../../../.
./include/c++/4.1.1/bits/iterator_concepts.h:65: error: declaration of 'concept 
std::IteratorAssociatedTypes<int>'

下列則是一般 g++ 所產出的錯誤訊息:

/usr/local/lib/gcc/powerpc-apple-darwin8.6.0/4.1.0/../../../../include/c++/4.1.0
/bits/stl_iterator_base_types.h: In instantiation of 'std::iterator_traits<int>'
:
/usr/local/lib/gcc/powerpc-apple-darwin8.6.0/4.1.0/../../../../include/c++/4.1.0
/bits/stl_algobase.h:309:   instantiated from '_OI std::__copy_aux(_II, _II, _OI
) [with _II = int, _OI = std::ostream_iterator<int, char, std::char_traits<char>
 >]'
/usr/local/lib/gcc/powerpc-apple-darwin8.6.0/4.1.0/../../../../include/c++/4.1.0
/bits/stl_algobase.h:326:   instantiated from 'static _OI std::__copy_normal<<an
onymous>, <anonymous> >::copy_n(_II, _II, _OI) [with _II = int, _OI = std::ostre
am_iterator<int, char, std::char_traits<char> >, bool <anonymous> = false, bool 
<anonymous> = false]'
/usr/local/lib/gcc/powerpc-apple-darwin8.6.0/4.1.0/../../../../include/c++/4.1.0
/bits/stl_algobase.h:387:   instantiated from '_OutputIterator std::copy(_InputI
terator, _InputIterator, _OutputIterator) [with _InputIterator = int, _OutputIte
rator = std::ostream_iterator<int, char, std::char_traits<char> >]'
test.cpp:8:   instantiated from here
/usr/local/lib/gcc/powerpc-apple-darwin8.6.0/4.1.0/../../../../include/c++/4.1.0
/bits/stl_iterator_base_types.h:129: error: 'int' is not a class, struct, or uni
on type
/usr/local/lib/gcc/powerpc-apple-darwin8.6.0/4.1.0/../../../../include/c++/4.1.0
/bits/stl_iterator_base_types.h:130: error: 'int' is not a class, struct, or uni
on type
/usr/local/lib/gcc/powerpc-apple-darwin8.6.0/4.1.0/../../../../include/c++/4.1.0
/bits/stl_iterator_base_types.h:131: error: 'int' is not a class, struct, or uni
on type
/usr/local/lib/gcc/powerpc-apple-darwin8.6.0/4.1.0/../../../../include/c++/4.1.0
/bits/stl_iterator_base_types.h:132: error: 'int' is not a class, struct, or uni
on type
/usr/local/lib/gcc/powerpc-apple-darwin8.6.0/4.1.0/../../../../include/c++/4.1.0
/bits/stl_iterator_base_types.h:133: error: 'int' is not a class, struct, or uni
on type

相較之下,ConceptGCC 的錯誤訊息明確程度有滿大改進(主要是長目錄名稱在亂)。其餘功能等我看完 papers 再貼心得(今天大概沒辦法)XD。

--
預計先看完 N2027, N2036 ~ N2042。

Blogger yen38/19/2006 6:23 pm 說:

相較之下,原本的訊息是很難以理解的,不過....似乎,學習C++的人觀念還要更好才行,從以前的型別錯誤改改就行,現在可能要學習更多,才能知道自己錯在那裡,未必不是一件好事。

 

<< 回到主頁