STL Benifits:
1.Code Reuse
2.Efficiancy and Fast
3.Accurate and less buggy
4.Simple code and readable
5.Standardized and helps in writing new libraries
Sequence Containers:
Vector Or List? :
Use vector
Random Access Iterator
Bi-Directional Iterator
Forward Iterator
Input Iterator
Const Iterator
Things to Remember:
1.Code Bloat : Template functions occupies own space for different types(Increases the object code)
2. For latest compilers square<int>(5) and square(5) are same. Where for class templates you have to explicitly specify the type.
3. template<class T> and template<typename T> are same.
4.Vector is dynamic array and can grow dynamically(its allocated on heap).
5. In STL, .end() points to one element after the last element.
6.Accessing a container using iterator is faster and proper approach than using the subscript.
7.Forward list has only forward iterator
8. Once created , then size of the array can not be changed.
9.Associative containers are implemented using binary tree.
10. Associative containers are always sorted.
11.Set and Map holds no duplicate keys, where Multi-Set and Multi-Map can hold duplicate key.s
12.Keys can not be modified in associative containers.
13. Functor : Class + Function
Overloads () operator and can maintain the state.
14. DO NOT use auto_ptr with STL containers as it transfers ownership , where as STL needs the elements to be copiable.
1.Code Reuse
2.Efficiancy and Fast
3.Accurate and less buggy
4.Simple code and readable
5.Standardized and helps in writing new libraries
Sequence Containers:
- Vector
- List
- DeQueue
- Array
- Forward List
- Set
- Multi-Set
- Map
- Multi-Map
Vector Or List? :
Use vector
- When you have insertions and deletions at the end
- Accessing elements is a frequent randomly
- Dynamically grows
- Insertions and deletions any where in the list is required.
- Random accessing is not a frequent activity.
Random Access Iterator
Bi-Directional Iterator
Forward Iterator
Input Iterator
Const Iterator
Things to Remember:
1.Code Bloat : Template functions occupies own space for different types(Increases the object code)
2. For latest compilers square<int>(5) and square(5) are same. Where for class templates you have to explicitly specify the type.
3. template<class T> and template<typename T> are same.
4.Vector is dynamic array and can grow dynamically(its allocated on heap).
5. In STL, .end() points to one element after the last element.
6.Accessing a container using iterator is faster and proper approach than using the subscript.
7.Forward list has only forward iterator
8. Once created , then size of the array can not be changed.
9.Associative containers are implemented using binary tree.
10. Associative containers are always sorted.
11.Set and Map holds no duplicate keys, where Multi-Set and Multi-Map can hold duplicate key.s
12.Keys can not be modified in associative containers.
13. Functor : Class + Function
Overloads () operator and can maintain the state.
14. DO NOT use auto_ptr with STL containers as it transfers ownership , where as STL needs the elements to be copiable.
Point 14 : auto_ptr is deprecated in new C++ standards
ReplyDeletePoint 9: I think it is binary search tree :)
point 3: You are correct. Item 42 has an interesting example to this. Good reading :)...
I mean Item 42 in Effective C++ by Scott Meyers in the comment above.
ReplyDelete