I'm on Linux; looking at the STL headers; they're really really complicated.
Is there, somewhere, a smaller version of STL that has the core features of the STL, but is actually readable?
Thanks!
I'm on Linux; looking at the STL headers; they're really really complicated.
Is there, somewhere, a smaller version of STL that has the core features of the STL, but is actually readable?
Thanks!
There is a book The C++ Standard Template Library, co-authored by the original STL designers Stepanov & Lee (together with P.J. Plauger and David Musser), which describes a possible implementation, complete with code - see http://www.amazon.co.uk/C-Standard-Template-Library/dp/0134376331.
Well, the STL is pretty complicated, so I think there's a certain amount of essential complexity going on here. It's not surprising that it may seem a little bewildering at first glance.
That said, maybe you could check out Borland's STLport and see if you find that an easier read.
The STL is a highly optimized library that does most of what it does by cleverly exploiting advanced features of C++ and the underlying compiler. Additionally, many things are inlined so there is no real bunch of code to look at like in an application. I'd recommend following Neil's advice.
I use the The C++ Standard Library: A Tutorial and Reference and can highly recommend it. Of course it is not something you read cover-to-cover, but is an very handy reference. Check out the reviews on Amazon as well.
Two key points stand out:
As a side note, you might have more success with the MSVC version because it's not trying to target multiple as many compilers. Compiler bugs and implementation-defined behavior result in various subtle workarounds. As those workarounds grow in number (as certainly happens when you add more compilers), the code can get gross fast.
For a more recent and thorough explanation of the "rules" of STL (such as iterators), check out a new book co-authored by Stepanov: http://www.elementsofprogramming.com/
If you enjoy mathematics, this book will excite you, because what the authors describe is essentially an algebra of computation. The site includes a sample chapter.
Note that Linux's STL headers have the tab stop set to six. Reconfigure your editor or replace tabs with six spaces and it should be much more readable.
RDESTL provides a 'small subset of STL functionality' (but also has some extras). I personally found the code quite instructive and easier to navigate than the big guys like STLPort or Dinkumware's implementation that ships with VC++.