CUJ:标准库:Allocator能做什么?[18]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 taodm 的 blog

inline bool operator!=(const malloc_allocator<t>&,

                       const malloc_allocator<t>&) {

  return false;

}

 

注:

[1] you can see an example of a pool allocator in the open source sgi pro64tm compiler, http://oss.sgi.com/projects/pro64/.

[2] why the funny template keyword in that expression? it's an annoying little technicality; like typename, it helps the compiler resolve a parsing ambiguity. the problem is that when a is a template parameter, and the compiler sees an expression like a::b<t>, the compiler doesn't know anything about a's members. should it assume that b<t> is a member template, or should it assume that b is an ordinary member variable and that < is just a less than sign? a human reader knows which way to interpret it, but the compiler doesn't. you need to put in template to force the first interpretation. formally, the rule (in §14.2 of the c++ standard) is: "when the name of a member template specialization appears after . or -> in a postfix-expression, or after nested-name-specifier in a qualified-id, and the postfix-expression or qualified-id explicitly depends on a template-parameter (14.6.2), the member template name must be prefixed by the keyword template. otherwise the name is assumed to name a non-template."

本文关键:CUJ、allocator、STL、Matt Austern
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top