Reputation: 17960
I have always been religiously using SGI's Standard Template Library Programmer's Guide (STLPG) as a reference manual whenever I implement something in C++ using the STL. Up until yesterday it has never failed me but yesterday I was working with std::vector at work and was pair programming with a colleague of mine who told me to use the assign method. I did not recognize this method which is unusual for me so I started digging through the std::vector part of the STLPG and there is no mention of any assign methods. My colleague pointed me to cpluplus.com's page on std::vector and lo and behold there it was along with a couple of other methods, such as at, that I also had never seen.
This confused me terrible so I went medieval on the problem and dug into */usr/include/c++/4.1.2/bits/stl_vector.h* which is copyright Hewlett-Packard Company 1994 and Silicon Graphics Computer Systems, Inc. 1996 and it contains implementations of both assign and at without any special commentary mentioning why they are omitted in the most recent copyright holders own documentation.
Is there anyone more seasoned than myself who could illuminate the community as to why these discrepancies exist and which online reference manual can I trust to be compliant with all modern STL implementation?
Upvotes: 6
Views: 335
Reputation: 146900
The SGI STL is the base of what's in the Standard, not exactly the same. Quite simply, it's been a very long time since 1994, like, seventeen years, so it's to be expected that in the meantime, some things changed. I personally use MSDN for my Standard library reference.
Upvotes: 1
Reputation: 3890
I usually use the C++ Reference, mainly because its Googles first hit if you search for something like c++ std vector
. But I have also found the information presented there accurate.
When in doubt I reference the latest working draft of the C++ Standard. (e.g. to answer your initial question chapter 23.3.6 [vector]) Of course this is then C++0x, which might not be fully supported yet, so you might want to check an older draft (i.e. the last one before C++03 was released).
Upvotes: 3
Reputation: 3984
SGI STL was implemented in 1997, and C++ standard was published in 1998.
If you want a reliable STL interface reference, look for C++ standard 2003. Or if you don't mind upgrading, the latest C++ draft is at http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf
In particular, if you go to N3242, section 23.3.6, you know there's assign and at.
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);
Upvotes: 1
Reputation: 92211
The SGI's STL is a library that in large parts was included in the ISO C++ Standard Library. Some parts were excluded, and a lot of other library components were added from other sources.
And, as you have noticed, some changes were made to improve or harmonize the interfaces to different components.
Even bigger changes will come later this year (hopefully) with a new C++11 standard, until now known as C++0x.
Upvotes: 3