Is there a readable implementation of the STL? [closed]

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!


Solution 1:

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.

Solution 2:

Yes, there is original implementation of the STL by Alexander Stepanov and Meng Lee. It is the most readable STL implementation I have ever seen. You can download it from here.

Below is an implementation of pair. Note how readable the source code really was:

#include <bool.h>

template <class T1, class T2>
struct pair {
    T1 first;
    T2 second;
    pair() {}
    pair(const T1& a, const T2& b) : first(a), second(b) {}
};

template <class T1, class T2>
inline bool operator==(const pair<T1, T2>& x, const pair<T1, T2>& y) { 
    return x.first == y.first && x.second == y.second; 
}

template <class T1, class T2>
inline bool operator<(const pair<T1, T2>& x, const pair<T1, T2>& y) { 
    return x.first < y.first || (!(y.first < x.first) && x.second < y.second); 
}

template <class T1, class T2>
inline pair<T1, T2> make_pair(const T1& x, const T2& y) {
    return pair<T1, T2>(x, y);
}

Back to the roots!

Solution 3:

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.