tags:

views:

525

answers:

8

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!

+15  A: 

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.

anon
+1  A: 

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.

John Feminella
Note, STLport is not a product by Borland. STLport is implemenation based on original SGI STL version. Borland just switched to STLport with in BCB6, but it does not maintain or own STLport project.
mloskot
+1  A: 

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.

Thorsten79
+3  A: 

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.

bahree
+1: This book is awesome.
280Z28
A great book, but one that does not address the question.
anon
+1  A: 

Two key points stand out:

  1. No implementation of the STL is readable without an understanding of the goals, rationale, benefits and limitations of the language itself, and general approach.
  2. Most implementations are readable once you have a deep understanding of (1) because the code is self-documenting on those premises. You might not like the formatting, but that really should be the least of your problems.

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.

280Z28
+1  A: 

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.

Jon Reid
+1  A: 

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.

Potatoswatter
+1  A: 

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++.

Eugen Constantin Dinca