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 月前3Implementing C++ Modules: Lessons Learned, Lessons Abandoned
Sample() // Retrieve an RSS feed and print it. { Uri uri(L""); SyndicationClient client; SyndicationFeed feed = co_await client.RetrieveFeedAsync(uri); for (auto&& item : feed.Items()) { hstring engineer ▪ The final throughput gain was had by finding that partial specializations of class templates dominated the compile time ▪ Let’s delay them... 46 (C) Dos Reis & DaCamara; CppCon 2021IDE Experience 0 码力 | 53 页 | 1.33 MB | 5 月前3Monadic Operations in Modern C++: A Practical Approach
public: virtual core::Expected:> add(const window::Uri& windowUri) = 0; }; ./ ... core::Expected:> WindowLayoutStack::add(const window::Uri& windowUri) { return loadWindow(windowUri, m_windowLoader) yout> m_windowLayout; }; 40Example: window layout wrapper void WindowLayout::add(const window::Uri& windowUri) { m_windowLayout:>add(windowUri).or_else(&printError); } 41What did we achieve? std::shared_ptrloadWindow( const window::Uri &windowUri, const window::Loader &loader); ./ ... bool WindowLayoutStack::add(const window::Uri& windowUri) { if (auto window = loadWindow(windowUri 0 码力 | 61 页 | 411.49 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 年前3
共 161 条
- 1
- 2
- 3
- 4
- 5
- 6
- 17