Presentation is loading. Please wait.

Presentation is loading. Please wait.

Standard Template Library Model

Similar presentations


Presentation on theme: "Standard Template Library Model"— Presentation transcript:

1 Standard Template Library Model
CSCE 121 Slides adapted from J. Michael Moore Based on slides created by Bjarne Stroustrup and Jennifer Welch

2 Basic STL Model iterators Algorithms sort, find, search, copy, …
Containers vector, list, map, unordered_map, … Separation of concerns Algorithms manipulate data, but don’t know about containers Containers store data, but don’t know about algorithms Algorithms and containers interact through iterators Each container has its own iterator types iterators

3 Iterators A single iterator is essentially the position of an element A pair of iterators defines a sequence the beginning (points to first element, if any) the end (points to the one-beyond-the-last element) begin: end:

4 Iterators … begin: Supports the “iterator operations”:
end: Supports the “iterator operations”: Go to next element: ++ Get value: * Check if two iterators point to same element: == Frequently a pointer type, but not necessarily Some iterators support more operations (--, +, [ ] )

5 One-Past-The-Last An iterator point to (refers to, denotes) an element of a sequence The end of the sequence is “one past the last element”, not the last element! Reason is to elegantly represent an empty sequence One-past-the last element is not an element you can compare an iterator pointing to it but you cannot dereference it (get its value) 1 2 3 the end: An empty sequence: begin: end: some iterator:

6 Containers Hold sequences in different ways vector 1 2 3

7 Containers Hold sequences in different ways list (doubly-linked) 1 2

8 Containers Hold sequences in different ways set (a kind of tree) 6 2 7
1 5 3 4


Download ppt "Standard Template Library Model"

Similar presentations


Ads by Google