Answer the question
In order to leave comments, you need to log in
Implementation of std::vector?
I want to learn true-way c++ programming, and therefore I'm wondering how to properly implement at least such a simple structure as a vector? Recommend a book or article that describes the process well and clearly.
I'm no longer interested in the vector itself, but in the thousands of nuances that arise when writing most containers: like the fact that you need to implement 2 access options by index: T&operator[] and const T&operator[], you need to correctly implement the copy constructor, the += operator must be a Vector& , and so on and so forth.
PS Yes, I know about stl, and I even wrote similar containers myself, even in pure C. The goal is not to write a bicycle, but to learn the correct style of writing production code. And yes, reading STL sources is, of course, an option, but not for me. I tried, for me it's a hodgepodge of characters randomly sketched into the editor.
Answer the question
In order to leave comments, you need to log in
> I'm no longer interested in the vector itself, but in the thousands of nuances that arise when writing most containers
. In my opinion, this is described in some article or book by Bjorn Stroustrup (I don't remember which one :) ). It is all these types of operators. Knowing the difference between a const and non-constant operator gives you hope that you can do it.
Also (in case you haven't seen it). you can read the well-known C++ FAQ, there is something mentioned about operators: www.parashift.com/c++-faq-lite/
As for the implementation, I suspect that you can’t do without templates here (well, unless you write a container for storing bytes and void links * and you will cast it all), so in the end something like STL sources should turn out.
As for the "competent style of writing", here, first of all, understandability, human readability and the correct names of identifiers are probably important.
I would suggest reading Jeff Alger's C++ for Real Programmers, it covers the nuances in a pretty simple way. There is nothing particularly difficult.
Here in this www.stepanovpapers.com/notes.pdf course of lectures by Stepanov (the creator of STL) they just design their vector with a thousand nuances.
You can read something from the following:
Scott Meyers - Effective STL, Effective C++
Stephen C. Dewhurst - C++ Common Knowledge: Essential Intermediate Programming, C++ Gotchas
Herb Satter - Exceptional C++, More Exceptional C++ Definitely a
direct answer to the question "How to write a vector ? there is not, but subtleties like the correct spelling of the copy constructor, etc. can be found there. All books are built in the "Question - Answer" format, so you can read from anywhere and choose what is interesting for you.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question