开发者

std::map and -fno-implicit-templates

开发者 https://www.devze.com 2023-01-10 23:51 出处:网络
I am trying to compile with g++ 4.4 and link a simple program that uses the STL. I am trying to do it using the -fno-implicit-templates so all templates must be instantiated explicitly.

I am trying to compile with g++ 4.4 and link a simple program that uses the STL. I am trying to do it using the -fno-implicit-templates so all templates must be instantiated explicitly.

I don't understand why this code works:

#include <map>
//template class std::map<char,char>;
template class std::_Rb_tree<char, std::pair <char const, char>,
               std::_Select1st<std::pair<char const, char> >, 
               std::less<char>, std::allocator<std::pair<char const, char> > >;

int main() {
   std::map <char,char> 开发者_运维知识库table;
return 0;
}

I would expect that this program needs the line: template class std::map<char,char>;, however that line does not make the program link. The std::_Rb_tree line is needed. Why?

Thanks in advance, any hint will be appreciated.


Maps use red-black trees in their implementation, so you have to explicitly instantiate the type of tree required for the instantiation of map. This does not look like a particularly useful compiler flag, IMHO.

0

精彩评论

暂无评论...
验证码 换一张
取 消