Writing an ITERATOR in C++

preview_player
Показать описание


This video is sponsored by DataCamp.
Рекомендации по теме
Комментарии
Автор

When I learn all C++17 features, C++34 going to be released.

muhammedyasinhanyasar
Автор

I'm a fairly seasoned C++ developer, having been using it since 2000. I enjoy your videos simply because I like to know how things are being taught today, and I like having a window into the game development world. Watching other people write and talk about code is also helpful for motivation!

lainproliant
Автор

I once had an interview at 343 and one of the questions the interviewers asked me was to write an iterator for a tree data structure. Up to that point, I had never written an iterator in C++ not to mention for a less common DS, so I struggled through it. Didn't get the job but I remember the experience. Those who are watching - learn this! It may help land you a job in the industry.

Thank you for this video - I found both the thought process and the code exercise useful!

mequint
Автор

Funny I just did an exam where I wished I had more knowledge on iterators and then decided to try and find more resources. Lo and behold! New video from the Cherno on iterators.

davidb
Автор

I always love when you explain library code

jessprogany
Автор

Thanks for your videos, always nice to watch! Question: why implement VectorIterator<T> instead of Iterator as a nested non-templated class in Vector? Is it because you could technically reuse it for another Array class (or any other random access container)?

joachimhodara
Автор

I'm all for reading code to learn, but my god, the STL seems like it was written as part of a contest to see who could write the most obfuscated and difficult to understand code.

PwnySlaystation
Автор

Exactly what I was waiting for. Thanks, Cherno! Waiting for more C++ DS Videos!

mockingbird
Автор

I love how you actually think about our learning experience and worry about it as a mentor would. Love you man. Keep up the great work!

kryt
Автор

"2:51 I pull my Heart and soul into my Videos " Words uttered from your subconcious mind, your efforts, burning desire towards tech. will take yoiu a long way, I watched couple of your videos, I'm so impressed by the way you deliver. Bridge the gap between a novice developer and an architect. I can see you there. God bless you Cherno.

sathyababu
Автор

dude you are awesome, thanks, i needed you, and you came to me. so grateful

joymakerRC
Автор

Thank you so much for your amazing lectures. Would you please make an introductory lecture on Boost Library? Where should we use it?
Also please make a video on different ways to design the code architecture in different types of large projects. Like thread based, or state machines based etc.

Lastly, the c++ coding standards.

I couldn't find good content on these topics so far. Thanks.

ibraheeminam
Автор

I've been waiting for this video for quite a while. Thank you Cherno!

isaactong
Автор

I would love a video about Iterators with a complex type, like a graph (a tree or something like hat). Everything in this video was easy, but what do you do, if you have to make a decision in the operator++? E.g. go to the child element or to a neighbor? And how do you track, which decision you made where? Lets say you go to the childs first, then you have to get the first neighbor after the last child. How do I do this, without creating a very complex iterator that has to track everything somehow?

LetsDark
Автор

Thanks; this was really useful and straight to the point.

Devilextremeful
Автор

Could someone explain me what the scope resolution operator :: is doing before the call of some operator() functions? Like ::operator new()

Byynx
Автор

why Vector::ValueType is used .I don't understand the syntax .I mean I only know that Classname::something is used when something is static in that class.Can anyone please explain that to me.thank you very much!

korara
Автор

Thanks Cherno - this is a nice "quick and dirty" implementation. For people interested to make solid safe real versions of the nice example here you must also: 1. add some protective code to prevent the increment/decrement operators from running off the ends of the array. 2. Decide how you want to handle dereferencing an iterator that is "invalid" (as well as pointer access). With a little work to tidy it up you can have a safe version. Mine currently will stop decrementing and "stay" on the first valid array value if you try to decrement off the end. I'm still thinking about best approaches and may test out the std behavior and just mimic same behaviors.

timhaynes
Автор

People just don't usually send me some good code they made to solve some industry problem that is at all readable. I'm not saying one of those things don't happen in the chain of events, none of those things exist in my life. So as a beginner I'm slightly lacking the source. And often times it also happens that you're trying to find a syntax for a simple problem you're trying to solve and think you know the way logically, but you're missing the correct syntax, and you find stack overflow doing some crazy convoluted method to what can be solved with a short line of code.

I'm at the level where I've never had to allocate to heap even though I've learned to do that. It's not quite the tools missing but applications. For most of my uses I'm interested in collecting a bit of information from the user or file, then operating on them and printing the results out. The biggest interest often is "how do I do this arithmetic operation chain in compact length with efficiency". Or "how on earth will I 1. make a matrix and print it 2. solve making an intuitive interface for inputing a matrix in prompt 3. do matrix calculations without writing painstaking manual element by element chain of loops or picking elements by hand 4. how do I generalize it for more than my template size matrix" etc.

Your operator overload (conveniently as a demonstration of x, y, z struct that represented a vector) solved the printing for virtually any custom class neatly inside the code. Also I saw a compact method from std libraries to sum the rows together as if you did M*(1, 1, 1) matrix calculation similar to some example exercises on vector math classes. But I also saw a demonstration of how you'd do nxn matrix multiplied with nxn matrix and got upset at like 5 nested for loops that you'd manually make to iterate through everything in the matrix (supposedly making it like 100 times slower than individual arithmetic operations would predict due to the way of using cache).

This is just semantics or philosophical pondering, not personally aimed to criticize or anything like that (all the videos are highly helpful) but don't you find it funny to state that most students have the issue of relying on documentation and videos when they should be reading real code and how the standard library does things, and also saying that when you wrote an iterator, you hadn't been taught it. In a video you released to demonstrate to people how to do it and giving tools to write and make things with code. I agree that you're correct in what you say, but what you do is immensely helpful, because I barely have time to sleep in engineering school and I assure you, learning C++ past very basics that allows you to write simple crude programs to maybe help you with some school tasks is not the priority. Without these videos I either wouldn't get a better understanding on C++ or I'd spent most of my time trying to understand stuff like CPPreference and bang my head against the wall to try to get some things to work and get no school work and studying done.

Lastly after all the rambling, I must say I love the hue of orange your Visual Studio has. I'm using VS Code because it seemed like the best combo for me: doesn't take ages to open up and seemingly have a lot of weight pulled around when you try to use it, but similar enough to Visual Studio with all the convenient editing help and tools. However it has in some sense quite pastel, light and faded. And I'm really struggling to customize it for now, there's no color map outside the template themes where you could just choose the type of thing to color and choose the color, it just throws you in an empty .json to write your own definitions in who knows what syntax. That's a future project, to make it look pleasantly vivid like your Visual Studio. Funnily enough VSC made sure I noticed from the coloring of the words that there was a } missing where you had it, everything was just grey instead of the variable colors because it would no longer declare the m_Data, m_size and m_Capacity.

Yupppi
Автор

I actually wrote my own vector class a couple of years ago and had the exact same issue with non primitive types. Took ages to figure out what was going wrong :D

mario