简介
ConceptGCC 派生自 GNU C++ compiler, 并实现了 ConceptC++. ConceptC++ 使C++的模板编程更容。因为编译器能在模板定义时做类型检查, 使得查错更加容易. 对泛型编程的完美支持也意味诸多在标准C++中所应用的模板技巧也不再需要了, 并且, 提供了比现在我们使用的C++编译器更好的错误信息。
ConceptGCC 包括了许多 ConceptC++ 的特征, 以提供对泛型编程的支持以及使C++模板程序的编写更加容易. ConceptC++ 的一个立竿见影的好处是 ConceptGCC 能给出模板使用错误的短小且有意义的错误信息。比如,用你现在使用的C++编译器编译下面的代码:
#include <list>
#include <algorithm>
using namespace std;
void f() {
list<int> l;
sort(l.begin(), l.end());
}
你可能会得到好几页的错误信息,在这些信息的最后一个说明了list迭代器没有定义 - 操作符. ConceptGCC 则只产生下面的错误信息:
sort.cpp: In function 'void f()':
sort.cpp:7: error: no matching function for call to 'sort(std::_List_iterator<int>, std::_List_iterator<int>)'
<path>: note: candidates are: void std::sort(_Iter, _Iter) [with _Iter = std::_List_iterator<int>] <where clause>
sort.cpp:7: note: no concept map for requirement 'std::MutableRandomAccessIterator<std::_List_iterator<int> >'
限制
ConceptGCC 只是一个原型, 一些 ConceptC++ 特性还没有实现. 我们希望将来能够实现它们. 已知的ConceptGCC 编译器的限制如下:
- 关联模板和函数模板没有实现.
- 模板内的泛型实例的类型检测 (e.g., vector<T>) 不稳定.
- ConceptGCC C++ 标准库 (改版的 libstdc++) 还没有完全转化到使用concept.
- 编译器还非常非常的慢且非常的不稳定.