Advanced Metaprogramming in Classic C++
- Length: 572 pages
- Edition: 1
- Language: English
- Publisher: Apress
- Publication Date: 2015-04-29
- ISBN-10: 1484210115
- ISBN-13: 9781484210116
- Sales Rank: #1340110 (See Top 100 Books)
Advanced Metaprogramming in Classic C++ aims to be both an introduction and a reference to C++ template metaprogramming (TMP); TMP is presented in the book as a set of techniques that will bring a new style in C++ and make code exceptionally clear and efficient. The book deals with language aspects, design patterns, examples and applications (seen as case studies). Special emphasis is put on small reusable techniques that will improve the quality of daily work.
What makes the book exceptional is the level of understanding of the concepts involved imparted by the author. This is not just a rote overview of metaprogramming. You will truly understand difficult topics like static assertions, how to write metafunctions, overload resolution, lambda expressions, and many others. More than that, you will work through them with practical examples guided by the author’s frank explanations. This book requires you to think and to learn and to understand the language so that you can program at a higher level.
What you’ll learn
- What templates and the small object toolkit are, and how to use them
- How to do overload resolution
- How to do metaprogramming with interfaces, algorithms, functors and refactoring
- How to work with code generators
- What is opaque type principle and how to use it
- How to work with debugging templates and more
Who this book is for
This book is for experienced C++ programmers who want to learn more.
Table of Contents
Chapter 1. Templates
Chapter 2. Small Object Toolkit
Chapter 3. Static Programming
Chapter 4. Overload Resolution
Chapter 5. Interfaces
Chapter 6. Algorithms
Chapter 7. Code Generators
Chapter 8. Functors
Chapter 9. Opaque Type Principle
Chapter 10. Refactoring
Chapter 11. Debugging Templates
Chapter 12. C++0X
Appendix A: Exercises
Appendix B: Bibliography
Title Copyright Dedication 1 Dedication 2 Contents at a Glance Contents About the Author About the Technical Reviewer Acknowledgments Preface Part I: #include <prerequisites> Chapter 1: Templates 1.1. C++ Templates 1.1.1. Typename 1.1.2. Angle Brackets 1.1.3. Universal Constructors 1.1.4. Function Types and Function Pointers 1.1.5. Non-Template Base Classes 1.1.6. Template Position 1.2. Specialization and Argument Deduction 1.2.1. Deduction 1.2.2. Specializations 1.2.3. Inner Class Templates 1.3. Style Conventions 1.3.1. Comments 1.3.2. Macros 1.3.3. Symbols 1.3.4. Generality 1.3.5. Template Parameters 1.3.6. Metafunctions 1.3.7. Namespaces and Using Declarations 1.4. Classic Patterns 1.4.1. size_t and ptrdiff_t 1.4.2. void T::swap(T) 1.4.3. bool T::empty() const; void T::clear() 1.4.4. X T::get() const; X T::base() const 1.4.5. X T::property() const; void T::property(X) 1.4.6. Action(Value); Action(Range) 1.4.7. Manipulators 1.4.8. Position of Operators 1.4.9. Secret Inheritance 1.4.10. Literal Zero 1.4.11. Boolean Type 1.4.12. Default and Value Initialization 1.5. Code Safety 1.6. Compiler Assumptions 1.6.1. Inline 1.6.2. Error Messages 1.6.3. Miscellaneous Tips 1.7. Preprocessor 1.7.1. Include Guards 1.7.2. Macro Expansion Rules Chapter 2: Small Object Toolkit 2.1. Hollow Types 2.1.1. instance_of 2.1.2. Selector 2.1.3. Static Value 2.1.4. Size of Constraints 2.2. Static Assertions 2.2.1. Boolean Assertions 2.2.2. Assert Legal 2.2.3. Assertions with Overloaded Operators 2.2.4. Modeling Concepts with Function Pointers 2.2.5. Not Implemented 2.3. Tagging Techniques 2.3.1. Type Tags 2.3.2. Tagging with Functions 2.3.3. Tag Iteration 2.3.4. Tags and Inheritance Part 2: #include <techniques> Chapter 3: Static Programming 3.1. Static Programming with the Preprocessor 3.2. Compilation Complexity 3.3. Classic Metaprogramming Idioms 3.3.1. Static Short Circuit 3.4. Hidden Template Parameters 3.4.1. Static Recursion on Hidden Parameters 3.4.2. Accessing the Primary Template 3.4.3. Disambiguation 3.5. Traits 3.5.1. Type Traits 3.5.2. Type Dismantling 3.6. Type Containers 3.6.1. typeat 3.6.2. Returning an Error 3.6.3. Depth 3.6.4. Front and Back 3.6.5. Find 3.6.6. Push and Pop 3.6.7. More on Template Rotation 3.6.8. Agglomerates 3.6.9. Conversions 3.6.10. Metafunctors 3.7. A Summary of Styles Chapter 4: Overload Resolution 4.1. Groups 4.1.1. From Overload to Groups 4.1.2. Runtime Decay 4.2. More Traits 4.2.1. A Function Set for Strings 4.2.2. Concept Traits 4.2.3. Platform-Specific Traits 4.2.4. Merging Traits 4.3. SFINAE 4.3.1. SFINAE Metafunctions 4.3.2. Multiple Decisions 4.3.3. Only_If 4.3.4. SFINAE and Returned Functors 4.3.5. SFINAE and Software Updates 4.3.6. Limitations and Workarounds 4.3.7. SFINAE with Partial Specializations 4.4. Other Classic Metafunctions with Sizeof 4.5. Overload on Function Pointers 4.5.1. Erase 4.5.2. Swap 4.5.2. Argument Dominance Chapter 5: Interfaces 5.1. Wrapping References 5.2. Static Interfaces 5.2.1. Static Interfaces 5.2.2. Common Errors 5.2.3. A Static_Interface Implementation 5.2.4. The Memberspace Problem 5.2.5. Member Selection 5.3. Type Hiding 5.3.1. Trampolines 5.3.2. Typeinfo Wrapper 5.3.3. Option_Map 5.3.4. Option_Parser 5.3.5. Final Additions 5.3.6. Boundary Crossing with Trampolines 5.4. Variant 5.4.1. Parameter Deletion with Virtual Calls 5.4.2. Variant with Visitors 5.5. Wrapping Containers Chapter 6: Algorithms 6.1. Algorithm I/O 6.1.1. Swap-Based or Copy-Based 6.1.2. Classification of Algorithms 6.1.3. Iterator Requirements 6.1.4. An Example: Set Partitioning 6.1.5. Identifying Iterators 6.1.6. Selection by Iterator Value Type 6.2. Generalizations 6.2.1. Properties and Accessors 6.2.2. Mimesis 6.2.3. End of Range 6.3. Iterator Wrapping 6.3.1. Iterator Expander 6.3.2. Fake Pairs 6.4. Receipts 6.5. Algebraic Requirements 6.5.1. Less and NaN 6.6. The Barton-Nackman Trick Chapter 7: Code Generators 7.1. Static Code Generators 7.2. Double checked Stop 7.3. Static and Dynamic Hashing 7.3.1. A Function Set for Characters 7.3.2. Changing Case 7.3.3. Mimesis Techniques 7.3.4. Ambiguous Overloads 7.3.5. Algorithm I/O 7.3.6. Mimesis Interface 7.4. Nth Minimum 7.5. The Template Factory Pattern 7.6. Automatic Enumeration of Types 7.7. If-Less Code 7.7.1. Smart Constants 7.7.2. Converting Enum to String 7.7.3. Self-Modifying Function Tables Chapter 8: Functors 8.1. Strong and Weak Functors 8.2. Functor Composition Tools 8.3. Inner Template Functors 8.3.1. Conversion of Functions to Functors 8.3.2. Conversion of Members to Functors 8.3.3. More on the Double Wrapper Technique 8.4. Accumulation 8.4.1. A Step-by-Step Implementation 8.5. Drivers 8.6. Algors 8.7. Forwarding and Reference Wrappers Chapter 9: The Opaque Type Principle 9.1. Polymorphic Results 9.2. Classic Lambda Expressions 9.2.1. Elementary Lambda Objects 9.2.2. Lambda Functions and Operators 9.2.3. Refinements 9.2.4. Argument and Result Deduction 9.2.5. Deducing Argument Type 9.2.6. Deducing Result Type 9.2.7. Static Cast 9.2.8. Arrays 9.3. Creative Syntax 9.3.1. Argument Chains with () and [] 9.4. The Growing Object Concept 9.4.1. String Concatenation 9.4.2. Mutable Growing Objects 9.4.3. More Growing Objects 9.4.4. Chain Destruction 9.4.5. Variations of the Growing Object 9.5. Streams 9.5.1. Custom Manipulators and Stream Insertion 9.5.2. Range Insertion with a Growing Object 9.6. Comma Chains 9.7. Simulating an Infix Part 3: #include <applications> Chapter 10: Refactoring 10.1. Backward Compatibility 10.2. Refactoring Strategies 10.2.1. Refactoring with Interfaces 10.2.2. Refactoring with Trampolines 10.2.3. Refactoring with Accessors 10.3. Placeholders 10.3.1. Switch-Off 10.3.2. The Ghost Chapter 11: Debugging Templates 11.1. Identify Types 11.1.1. Trapping Types 11.1.2. Incomplete Types 11.1.3. Tag Global Variables 11.2. Integer Computing 11.2.1. Signed and Unsigned Types 11.2.2. References to Numeric Constants 11.3. Common Workarounds 11.3.1. Debugging SFINAE 11.3.2. Trampolines 11.3.3. Compiler Bugs Chapter 12: C++0x 12.1. Type Traits 12.2. Decltype 12.3. Auto 12.4. Lambdas 12.5. Initializers 12.6. Template Typedefs 12.7. Extern Template 12.7.1. Linking Templates 12.7.2. Extern Template 12.9. Variadic Templates Appendix A: Exercises A.1. Exercises A.1.1. Extension A.1.2. Integer A.1.3. Date Format A.1.4. Specialization A.1.5. Bit Counting A.1.6. Prime Numbers A.1.7. Typeinfo without RTTI A.1.8. Hints and Partial Solutions Appendix B: Bibliography Index
Donate to keep this site alive
How to download source code?
1. Go to: https://github.com/Apress
2. In the Find a repository… box, search the book title: Advanced Metaprogramming in Classic C++
, sometime you may not get the results, please search the main title.
3. Click the book title in the search results.
3. Click Code to download.
1. Disable the AdBlock plugin. Otherwise, you may not get any links.
2. Solve the CAPTCHA.
3. Click download link.
4. Lead to download server to download.