Any STL source code easy to read?

I've decided to read source code of STL,is there any material about it?
Since c++ has changed a lot in the past ten years,I suspect that books written
ten years ago are still useful for learning generic progromming.
I don't want to lost in details of algorithms,since i am not expecting being a expert at data structures and algorithms,So i am wondering whether it's a good choice to read STL source code.
any suggestion?
> So i am wondering whether it's a good choice to read STL source code.

Read standard library source code shipped with an implementation? Not a good choice for learning how to use the library.

To get an idea of what it is, start with the simplest parts (where you will not be overwhelmed by low level details about the platform and the innards of the compiler). Algorithms and function objects are good places to start.

Possible implementations given in cppreference.com is very readable. For instance:
http://en.cppreference.com/w/cpp/algorithm/adjacent_find
I've decided to read source code of STL,is there any material about it?

Assuming you're referring to the C++ standard library (based on "c++ has changed a lot in the past ten years") and not the HP/SGI library called "STL", which was abandoned over a decade ago, there is no "source code of STL". There is a set of requirements to the interface and to the runtime complexity of the standard library (including the containers library, the algorithm library, and the functional library, which were once heavily based on the interfaces of STL the library), and each C++ compiler vendor finds its own way to satisfy them.

As JLBorges pointed out, it's not a good way to learn to use it, but there is occasional merit in looking up the source code of a standard library implementation. Personally, I find libc++ to be most clearly written: http://llvm.org/svn/llvm-project/libcxx/trunk/include/
Another one that's online browsable is GNU stdlibc++: http://gcc.gnu.org/viewcvs/gcc/trunk/libstdc%2B%2B-v3/include/ although it's burdened with backwards compatibility and lacks a few components of modern C++ (e.g. the codecvt header)
Last edited on
I've known how to use standary library very well.Now i wanna learn some technologies about generic progrmming,for example,in the adjacent_find,
the realistic implementation code as declaration may be something like that:
template<typename Iter>
Enable_if<Forward_iterator<Iter>(),Iter>adjacent_find( Iter first, Iter last );
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using namespace std;
template<bool B,typename T=void>
using Enable_if = typename enable_if<B,T>::type;

template<typename T>
struct forward_iterator{};
template<>
struct forward_iterator<forward_iterator_tag>:true_type{};
template<>
struct forward_iterator<bidirectional_iterator_tag>:true_type{};
template<>
struct forward_iterator<random_access_iterator_tag>:true_type{};

template<typename Iter>
constexpr bool Forward_iterator ( )
 {
    return forward_iterator<typename iterator_traits<Iter>::iterator_category>::value;
}

template<typename Iter>
Enable_if<Forward_iterator<Iter>(),Iter> my_adjacent_find(Iter f, Iter e  )
{
    //algorithm here
}

I care about generic progrmming neither using STL nor data structures and algotithms ,but i find myself got lost in details of implementation of sophisticated data structures and algorithms easily when reading these codes.
Is some STL implementation worth reading?what about SGI STL?
Last edited on
> i wanna learn some technologies about generic progrmming
> Is some STL implementation worth reading?what about SGI STL?

IMHO, books may be a better way to get introduced to generic progrmming techniques. Looking at the actual source code for a standard library implementation could be something that you could do in parallel.

For instance:

Advanced C++ Metaprogramming by Di Gennaro
http://www.amazon.com/Advanced-Metaprogramming-Davide-Di-Gennaro/dp/1460966163

C++ Templates: The Complete Guide by Vandevoorde and Josuttis
http://www.amazon.com/C-Templates-The-Complete-Guide/dp/0201734842

Modern C++ Design: Generic Programming and Design Patterns Applied by Andrei Alexandrescu
http://www.amazon.com/Modern-Design-Generic-Programming-Patterns/dp/0201704315
Topic archived. No new replies allowed.