Where to download C ++ STLsource code for both .h and .cpp files?

I downloaded the STL source code from http://www.sgi.com/tech/stl/download.html , but it only has .h for function declaration. Where can I download .cpp files to read the actual implementation?

For example, in stl_multimap.h or in stl_map.h it has:

template <class _Key, class _Tp, class _Compare, class _Alloc> inline void swap(multimap<_Key,_Tp,_Compare,_Alloc>& __x, multimap<_Key,_Tp,_Compare,_Alloc>& __y) { __x.swap(__y); } 

I want to know the actual swap implementation, as in

 __x.swap(__y); 

I do not see where the actual code for the swap is. Here he simply calls himself.

+4
source share
8 answers

.H files contain implementations. Many of the headers on this page are just wrappers around other headers or provide typedefs, but if you look at a file like stl_set.h , you will see that it has all the function definitions for the set class.

Even the page itself states that this is a header-only library, which means implementations are included in the headers.

+4
source

The implementation of the C ++ library depends on different compilers / systems. If you use GCC / g ++ as your compiler, here you can download the source code http://gcc.gnu.org/libstdc++/ .

Or you can anonymously check the source code here: svn checkout svn: //gcc.gnu.org/svn/gcc/trunk/libstdc++-v3 libstdC ++

+5
source

STL is a template library. I hope you find the implementation only in the header files.

+3
source

This is not something else. Please note that the page says:

This STL distribution consists entirely of header files: no need to link to library files

+2
source

Implementations are all in header files. You must do this using templates .: - /

+1
source

You can find the implementation for swap in std_algobase.h .

+1
source

SGI STL file names begin with "stl _".

For example, the implementation of the SGI version vector is in the stl_vector.h file.

0
source

Below is the code for swap and iter_swap inside stl_algobase.h file

 // swap and iter_swap template <class _ForwardIter1, class _ForwardIter2, class _Tp> inline void __iter_swap(_ForwardIter1 __a, _ForwardIter2 __b, _Tp*) { _Tp __tmp = *__a; *__a = *__b; *__b = __tmp; } template <class _ForwardIter1, class _ForwardIter2> inline void iter_swap(_ForwardIter1 __a, _ForwardIter2 __b) { __STL_REQUIRES(_ForwardIter1, _Mutable_ForwardIterator); __STL_REQUIRES(_ForwardIter2, _Mutable_ForwardIterator); __STL_CONVERTIBLE(typename iterator_traits<_ForwardIter1>::value_type, typename iterator_traits<_ForwardIter2>::value_type); __STL_CONVERTIBLE(typename iterator_traits<_ForwardIter2>::value_type, typename iterator_traits<_ForwardIter1>::value_type); __iter_swap(__a, __b, __VALUE_TYPE(__a)); } template <class _Tp> inline void swap(_Tp& __a, _Tp& __b) { __STL_REQUIRES(_Tp, _Assignable); _Tp __tmp = __a; __a = __b; __b = __tmp; } 
0
source

All Articles