views:

264

answers:

5

If I were to buy one and only one book on C++ templates which one would you recommend ? And why ?

+13  A: 

C++ Templates - The Complete Guide. By two very active members of the C++ community, well-written, covers everything in the current C++ standard you are likely to want to know.

anon
A: 

I'd buy the latest edition of Stroustrups C++ books, because that is the ultimate language reference.

It isn't the ultimate language reference, and it isn't particularly strong on templates.
anon
Neil: What would be the ultimate language reference, then? (Or are you referring to the actual standard specification?)
Hans W
@Hans Yes - that's the ultimate reference. And even as a non-ultimate reference, I think TC++PL has failings.
anon
+5  A: 

C++ Templates: The Complete Guide is the book - although it is a bit aged (in the sense that compilers have changed since - e.g. some of the example code in the book did not compile with VC++ 2005), AFAIK there is no newer.

Alexandrescu's Modern C++ Design also contains very interesting and wild stuff about things you can do with templates.

Péter Török
MC++D is of course even more aged :-)
anon
And before blaming the code in the book, you should at least consider that the fault might lie with VC++2005.
anon
@Neil I did. I am not a fan of VC++ and I know that its implementation often differs from the standard. Still, it makes the book more difficult to use if its code does not (always) compile with <your current C++ compiler here> - that's the only thing I wanted to point out.
Péter Török
@Neil OK, I was wrong regarding the age of the two books, sorry.
Péter Török
+1  A: 

It is not a standard template book, but it shows the beauty of templates for metaprogramming with C++. This I would recommend as a second book to learn the depths of template programming with C++:

C++ Template Metaprogramming

Rupert Jones
Indeed, a most useful read as it allows to illustrate in depths both the strengths and shortcomings of templates in C++ and (because of metaprogramming) explores the often ignored complexity aspects.
Matthieu M.
+1  A: 

I like Andrei Alexandrescu's Modern C++ Design: Generic Programming and Design Patterns Applied better than "C++ Template Metaprogramming" -- it's the book I learned templates from, even though it's not presented as a beginner book. It's certainly not for beginners in programming, but it's a fabulous way of exploring what templates are really good for with practical examples that will blow your mind.

I spent a week on chapter 3 and got the most wonderful dreams from it, and then never viewed generic programming the same way again.

Ether