STL C++ Iterators - Writing an iterator from scratch | Modern Cpp Series Ep. 138
Mike Shah
View ChannelAbout
Teaching computer Science, primarily Modern C++, C, DLang, games, and computer graphics programming I'm a teaching professor and Senior 3D Graphics Engineer who has worked in industry at various games and graphics companies. Access Full Courses: courses.mshah.io Free Community Forum: https://courses.mshah.io/communities/Q29tbXVuaXR5LTI3MzAz
Latest Posts
Video Description
►Full C++ Series Playlist: https://www.youtube.com/playlist?list=PLvv0ScY6vfd8j-tlhYVPYgiIyXduu6m-L ►Find full courses on: https://courses.mshah.io/ ►Join as Member to Support the channel: https://www.youtube.com/channel/UCA64pZbN5Mz5NxC3SO4qpDg/join ►Lesson Description: In this lesson I show you how to write an iterator from scratch that is compatible with range-based for-loops. We'll set the stage for how to also make this iterator compatible with several std::algorithm STL algorithms as well! 00:00 Introduction 00:58 Iterators review and use 03:50 Example of STL vector and usage with iterators 05:40 Cpp insights view of ranged-based for loops and iterators 08:00 Swapping STL data structures 08:45 Figuring out which member functions we need for iterators 09:41 Example data structure explanation 11:40 Adding 'begin' and 'end' stubs and 'iterator' struct 14:00 Adding 'struct iterator' 14:40 Design Decision on our iterators bookkeeping strategy 15:25 iterator Constructor 16:12 Idea that we can have multiple iterators to same container 17:20 Cleaning up our iterator, inspired by STL design 18:30 Placeholders for distance (ptrdiff_t) 19:40 Placeholder for iterator category 21:40 Filling out 'begin' and 'end' 23:28 'end' is beyond the data structure 24:58 Implementing pre increment and post increment 29:07 Dereference operator 31:00 Adding arrow operator 32:53 Implementing "operator==" and "operator!=" 35:20 Fixing bug with pre increment 36:00 WORKING iterator -- very cool! 37:40 Review of our implementation 40:30 Wrap up and thank you to our members and subscribers ►YouTube Channel: https://www.youtube.com/c/MikeShah ►Please like and subscribe to help the channel! ►Join our free community: https://courses.mshah.io/communities/Q29tbXVuaXR5LTI3MzAz
Boost Your C++ Skills: Essential Tools
AI-recommended products based on this video




