开发者

unfamiliar with struct/class declaration with template

开发者 https://www.devze.com 2023-01-04 03:28 出处:网络
while going through some of the mili source code I came across a struct declared like this: template <class T, class Pre, class Pos>

while going through some of the mili source code I came across a struct declared like this:

template <class T, class Pre, class Pos>
struct PrePosCaller<T*, Pre, Pos>

(from here)

The part I'm unfamiliar with is <T*, Pre, Pos>. I understand what the code does and its purpose in this context but 开发者_运维技巧I would like to know where it is documented so I can learn/understand it a bit more.


I would like to know where it is documented

If you are looking for an introduction as well as background to the subject, get yourself a copy of C++ Templates: The Complete Guide.
While the definitive documentation is the C++ standard itself, its no fun to approach it without a well written overview.


That is a template specialization. In particular a partial specialization.

Somewhere in the code there is a template declared as:

template <class T, class Pre, class Pos>
struct PrePosCaller { //...
};

or something similar. Then they are providing an specialization of that template for the cases where the first argument is a pointer type. That is, this is a template definition for PrePosCaller when the first argument of the template is a pointer.


Thinking in C++ Vol. 2 provides a pedagogical view on templates and some related techniques. It is also an excellent read about C++ in general. And it is free.

0

精彩评论

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