Original article from the C++ report 95 about the CRTP online anywhere?
I've just learned about the CRTP Pattern and am looking for the original work. The reference of wikipedia says
Coplien, James O. in (1995, Fe开发者_高级运维bruary). "Curiously Recurring Template Patterns". C++ Report: 24–27.
I also found it on ACM, however it's not available for download :( I wonder if anybody still has it.
I just uploaded it to http://sites.google.com/a/gertrudandcope.com/info/Publications/InheritedTemplate.pdf. Enjoy.
It was included in the book C++ Gems, which is still available on Amazon and from used book sellers. The bulk of the article is also available in Google Books.
You might be over-thinking this one a bit. The name itself "curiously recurring..." implies the author, or whoever labeled it "CRTP", noticed that many places have already been using this technique, so the practice of making base class template parameter the deriving class itself has been around before the term was coined.
Overall, there's not that much to CRTP. It's so popular because it allows to recreate virtual function behavior without actually having virtual functions and the problem with the actual virtual functions is that a) they require an extra indirection (few more assembly instructions, not that big of a deal) and b) most of the time they can't be optimized away by the compiler (larger deal). This is why CRTP became so popular especially in library code like STL, Boost or ATL where you have framework classes with one- or two-liner methods. You get fast virtual call at the expense of giving up polymorphic behavior, which is not needed a lot of the time anyway.
If you think you are comfortable with C++ templates and ready to take it to the next step, I suggest you read "Modern C++ Design: Generic Programming..." or "C++ Template Metaprogramming - Concepts...". I've been coding C++ for a long time now and generally comfortable with just about anything, but first time I picked up one of these books, the things they showed had me blown away.
In case you decide to actually pick up one of those books, I just want to point out that I liked "Modern C++ Design..." and it used very human approach to not-so-straightforward things, it is based on Loki library, which as far as I can tell is no longer maintained. On the other hand, the other book (which I only used as a reference few times) describes Boost MPL library which is very much alive and well. Both books talk about the same techniques of metaprogramming (code execution at compile time) using C++ templates.
精彩评论