Modern C++ Iterators
josuttis.com 1 C++ Stop Putin Stop war Nicolai M. Josuttis josuttis.com @NicoJosuttis 10/23 Iterators ©2023 by josuttis.com 2 C++ Nicolai M. Josuttis • Independent consultant – Continuously learning Nico Josuttis Modern C++ 2023-10-03 @CppCon 1©2023 by josuttis.com 3 C++ Stop Putin Stop war Iterators Modern C++ ©2023 by josuttis.com 4 C++ Loop Over Arrays • Two ways to iterate over the elements Undefined Behavior C/C++ Nico Josuttis Modern C++ 2023-10-03 @CppCon 2©2023 by josuttis.com 5 C++ Iterators: Generalization of Pointers that Iterate • Iterate like a pointer over elements – From begin()0 码力 | 24 页 | 1.93 MB | 5 月前3Back to Basics: Classic 9STL
Classic STL Copyright © 2021 Bob Steagall Overview • Rationale • History and design overview • Iterators • Containers • Algorithms 2CppCon 2021 – Back to Basics: Classic STL Copyright © 2021 Bob Steagall Steagall Goals and References • Goals • Understand overall STL design • Understand iterators • Recommended references • The Standard C++ Library, Second Edition Nicolai M. Josuttis – Addison-Wesley What is "Classic STL?" 4 Language Support Concepts Diagnostics General Utilities Containers Iterators Algorithms Strings Ranges Numerics Time Localization Input/Output Regular Expressions Atomic0 码力 | 75 页 | 603.36 KB | 5 月前3Some Things C++ Does Right
There’s no need for special case functions; C++ requires you to know some basic principles (iterators, half-open ranges) and one can build from theseA word about beauty and elegance // ... int main() careful due to template specializations!Sometimes unnoticed upsides of iterators 178Sometimes unnoticed upsides of iterators • Situation: we want to write our own « reverse » in order to reverse upsides of iterators templatevoid rev(It b, It e) { using std::swap; while(b != e) { --e; if(b == e) return; swap(*b, *e); ++b; } } 180Sometimes unnoticed upsides of iterators template 0 码力 | 228 页 | 2.47 MB | 5 月前3Iteration Revisited
6ITERATION REVISITED STL ITERATORS ▸ STL iterators are a generalisation of array pointers ▸ Advantages: ▸ Powerful ▸ Low overhead ▸ “Natural” syntax ▸ Disadvantages: ▸ Iterators are just as unsafe REVISITED 9ITERATION REVISITED ITERATORS AND UB ▸ Dereferencing a past-the-end iterator is UB auto iter = std�::end(rng); do_something(*iter); 10ITERATION REVISITED ITERATORS AND UB ▸ Incrementing a past-the-end random—access jumps auto iter = std�::end(rng); �++iter; 11ITERATION REVISITED ITERATORS AND UB ▸ Dangling iterators can occur easily ▸ Any operation on a dangling iterator is UB auto min_iter(const0 码力 | 56 页 | 5.27 MB | 5 月前3Nim 2.0.8 Manual
will be executed at compile time cannot use the following language features: methods closure iterators the cast operator reference (pointer) types FFI The use of wrappers that use FFI and/or cast statement Example: The yield statement is used instead of the return statement in iterators. It is only valid in iterators. Execution is returned to the body of the for loop that called the iterator. Yield execution is passed back to the iterator if the next iteration starts. See the section about iterators (Iterators and the for statement) for further information. Block statement Example: The block statement0 码力 | 132 页 | 5.73 MB | 1 年前3Computer Programming with the Nim Programming Language
Procedures and functions Object-oriented programming and inheritance Other builtin data types Iterators Templates Casts and type conversions Bitwise operations Exceptions Destructors Finalizers compile itself in less than 10 seconds on a modern PC. Modern concepts such as zero-overhead iterators, compile-time evaluation of user-defined functions, and cross-module inlining, in combination statements, expressions, conditional and iterative code execution, as well as functions, procedures, iterators, templates, and exceptions. We will also discuss various basic data types, including the container0 码力 | 865 页 | 7.45 MB | 1 年前3Computer Programming with the Nim Programming Language
Procedures and functions Object-oriented programming and inheritance Other builtin data types Iterators Templates Casts and type conversions Bitwise operations Exceptions Destructors Finalizers compile itself in less than 10 seconds on a modern PC. Modern concepts such as zero-overhead iterators, compile-time evaluation of user-defined functions, and cross-module inlining, in combination statements, expressions, conditional and iterative code execution, as well as functions, procedures, iterators, templates, and exceptions. We will also discuss various basic data types, including the container0 码力 | 784 页 | 2.13 MB | 1 年前3Computer Programming with the Nim Programming Language
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 For loops and iterators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402 Pragma macros for iterators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .0 码力 | 508 页 | 3.50 MB | 1 年前3Computer Programming with the Nim Programming Language
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 For loops and iterators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402 Pragma macros for iterators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .0 码力 | 508 页 | 3.54 MB | 1 年前3Computer Programming with the Nim Programming Language
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 For loops and iterators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402 Pragma macros for iterators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .0 码力 | 508 页 | 3.50 MB | 1 年前3
共 484 条
- 1
- 2
- 3
- 4
- 5
- 6
- 49