Are there any differences in the STL C ++ standard?

I have always religiously used the SGI Standard Template Programming Guide (STLPG) as a reference guide whenever I implement something in C ++ using STL. Until yesterday it never let me down, and yesterday I worked with std :: vector at work and was a programmer with my colleague who told me to use the assignment method. I did not recognize this method, which is unusual for me, so I started digging through the std :: vector part of STLPG, and there is no mention of any assign methods. My colleague pointed me to the cpluplus.com page on std :: vector , and there he was, along with several other ways, such as that I had not seen.

This embarrassed me terribly, so I went into the Middle Ages on the issue and buried myself in * / usr / include / C ++ / 4.1.2 / bits / stl_vector.h *, which is copyright of Hewlett-Packard Company 1994 and Silicon Graphics Computer Systems , Inc 1996, and it contains implementations of both the nominated and without any special comments that mention why they are not listed in the most recent copyright owner documentation.

Is there anyone more experienced than me who could illuminate the community as to why these inconsistencies exist and which online help guide I can trust to be compatible with all of today's STL implementations?

+6
source share
4 answers

I usually use the C ++ Reference , mainly because its Googles first hit if you are looking for something like c++ std vector . But I also found the information presented there accurate.

In case of doubt, I refer to a working working draft of the C ++ standard . (for example, to answer your initial question, chapter 23.3.6 [vector]) Of course, this means that C ++ 0x, which may not be fully supported, so you can check the old draft (i.e. the last to C + +03 was released).

+3
source

SGI STL is a library in which it has been included in large parts in the standard ISO C ++ library. Some parts were excluded, and many other library components were added from other sources.

And, as you noticed, some changes have been made to improve or harmonize interfaces with various components.

Even bigger changes will come later this year (hopefully) with the new C ++ 11 standard, still known as C ++ 0x .

+3
source

SGI STL was introduced in 1997, and the C ++ standard was published in 1998.

If you need a reliable reference to the STL interface, look at the C ++ 2003 standard. Or if you don't mind updating, the latest C ++ project is at http://www.open-std.org/jtc1/sc22/wg21/ docs / papers / 2011 / n3242.pdf

In particular, if you go to section 23.3.6 of N3242, you know what to designate it in.

 template <class InputIterator> void assign(InputIterator first, InputIterator last); 

Effects:

 erase(begin(), end()); insert(begin(), first, last); 

and

 void assign(size_type n, const T& t); 

Effects:

 erase(begin(), end()); insert(begin(), n, t); 

and

 const_reference at(size_type n) const; reference at(size_type n); 
+1
source

SGI STL is the foundation of what's in the standard, and not the same. Simply put, it has been a very long time since 1994, for example, seventeen years, so it was to be expected that at the same time some things had changed. I personally use MSDN to link to my standard library.

+1
source

Source: https://habr.com/ru/post/885478/


All Articles