Back to Basics: Templates Part 2
Basics: Templates – Part 2 Bob Steagall CppCon 2021CppCon 2021 – Back to Basics: Templates – Part 2 Copyright © 2021 Bob Steagall Recap: Templates • C++ supports generic programming with templates • A kinds of templates • Function templates • Class templates • Member function templates • Alias template • Variable templates • Lambda templates 2CppCon 2021 – Back to Basics: Templates – Part 2 Copyright inclusion preprocessing directives (#ifdef) • And all macros expanded 3CppCon 2021 – Back to Basics: Templates – Part 2 Copyright © 2021 Bob Steagall Recap: Declarations and Definitions • A name is an identifier0 码力 | 80 页 | 490.15 KB | 5 月前3Back to Basics: Templates - Part 1
Back to Basics: Templates – Part 1 Bob Steagall CppCon 2021CppCon 2021 – Back to Basics: Templates – Part 1 Copyright © 2021 Bob Steagall Overview • Rationale • Template fundamentals • Template categories categories in detail 2CppCon 2021 – Back to Basics: Templates – Part 1 Copyright © 2021 Bob Steagall Goals and References • Goals • Cover major features • Explain some important terminology and concepts concepts • Point to next steps • Recommended references • C++ Templates The Complete Guide, Second Edition David Vandevoorde, Nicolai M. Josuttis, Douglas Gregor – Addison-Wesley 2018 • Effective Modern0 码力 | 68 页 | 436.75 KB | 5 月前3Back to Basics: C++ Templates - Part 1
Info @Andreas__Fertig B2B: C++ Templates Part 1 fertig adjective /ˈfɛrtɪç/ finished ready complete completed Andreas Fertig v1.0 B2B: C++ Templates 2 B2B: C++ Templates Part 1 © 2020 Andreas Fertig flexi bility. Andreas Fertig v1.0 B2B: C++ Templates 3 Templates ■ Templates are a kind of pattern for the compiler. ■ We can instantiate templates with different types or values. ■ Each instantiation ment. ■ Templates reduce a lot of writers’ work. We do not have to implement functions multiple times just because it’s a slightly different type. ■ There are different types of templates: ■ Functiontemplates0 码力 | 17 页 | 817.47 KB | 5 月前3Back to Basics: C++ Templates - Part 2
Fertig https://AndreasFertig.Info post@AndreasFertig.Info @Andreas__Fertig B2B: C++ Templates Part 2 Variadic templates: Parameter pack ■ Syntax: A typename|class... Ts generates a type template pa rameter B2B: C++ Templates 2 B2B: C++ Templates Part 2 © 2020 Andreas Fertig https://AndreasFertig.Info post@AndreasFertig.Info 1Variadic templates ■ With C++11, there are variadic templates: ■ Variadic Variadic templates are templates that take any number of parameters. ■ Already known by variadic macros or variadic functions. 1 A Helper functions to convert everything into a std::string 2 auto Normalize(const0 码力 | 12 页 | 787.22 KB | 5 月前3EXPLORATION OF C++20 METAPROCRAMMING
math. 2MOTIVATION • Templates are a powerful tool for C++ programmers. • Each C++ version has evolved templates, allowing better usage. • We’ll see the value of adding templates to your code. 3MOTIVATION use of templates 4 • We’ll see how C++20 creates a paradigm shift in the way we use metaprogramming. And I don’t blame them…• Part 0: (Prologue) What are templates? • Part I: Adding templates to existing beyond…) • Part V: Advanced methods for controlling compile time logic OUTLINE 5PART 0: WHAT ARE TEMPLATES? 6• A template allows creating a class or a function templateclass TemplatedClass 0 码力 | 50 页 | 2.59 MB | 5 月前3Back to Basics: Generic Programming
different, unrelated types Static polymorphism9 David Olsen – Generic Programming CppCon 2024 C++ Templates Same code works on different, unrelated types Static polymorphism10 David Olsen – Generic Programming correctness of the definition46 David Olsen – Generic Programming CppCon 2024 Substitution Class templates Substitution without instantiation in two contexts Incomplete type is sufficient Class template template arguments are checked47 David Olsen – Generic Programming CppCon 2024 Substitution Class templates Substitution without instantiation in two contexts Incomplete type is sufficient Class template0 码力 | 175 页 | 1.16 MB | 5 月前3Just-In-Time Compilation: The Next Big Thing
symbol with no templates 6 . 12SAVE LIBRARY/BINARY SAVE LIBRARY/BINARY MAIN.CPP MAIN.CPP #include// std::stoi void dispatch(int); // _Z3dispatchi - Mangled symbol with no templates int main(int #include // std::stoi void dispatch(int); // _Z3dispatchi - Mangled symbol with no templates int main(int argc, const char** argv) { dispatch(std::stoi(argv[1])); } $LLC -filetype=obj #include // std::stoi void dispatch(int); // _Z3dispatchi - Mangled symbol with no templates int main(int argc, const char** argv) { dispatch(std::stoi(argv[1])); } $LLC -filetype=obj 0 码力 | 222 页 | 5.45 MB | 5 月前3Modern C++ Tutorial: C++11/14/17/20 On the Fly
. . . . . . . . . . 26 2.5 Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 3 CONTENTS CONTENTS Extern templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Type alias templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Variadic templates . . . . . . . . . . . . . . . . . . . . . . t) { return t + 0.001; } int main() { std::cout << print_type_info(5) << std::endl; 25 2.5 Templates CHAPTER 02: LANGUAGE USABILITY ENHANCEMENTS std::cout << print_type_info(3.14) << std::endl; }0 码力 | 92 页 | 1.79 MB | 1 年前3Design Patterns
that object-oriented programming and especially its theory is overestimated. … C++ always had templates, and now also has std::variant, which makes most of the use of inheritance unnecessary.” (Unknown that object-oriented programming and especially its theory is overestimated. … C++ always had templates, and now also has std::variant, which makes most of the use of inheritance unnecessary.” (Unknown There is no architecture! 🤕Templates to the Rescue (?) 109 ”I believe that object-oriented programming and especially its theory is overestimated. … C++ always had templates, and now also has std::variant0 码力 | 136 页 | 7.95 MB | 5 月前3Back to Basics - Function Call Resolution
multiple functions with the same name, including: name hiding function overloading function templates When a compiler encounters an expression like f(x, y, z), it must consider each of these language Function overloading and overload resolution Name lookup Default function arguments Function templates For each feature, we’ll explain first how it works on its own, and then how it interacts with features. 9 Outline Function Overloading Name Lookup Default Function Arguments Function Templates Tying It All Together 10Back to Basics - Function Call Resolution Copyright © 2024 by Ben Saks0 码力 | 44 页 | 1.30 MB | 5 月前3
共 160 条
- 1
- 2
- 3
- 4
- 5
- 6
- 16