Learn how pairs and tuples are useful where you need a fixed number of strongly typed values and why a pair or tuple is often more convenient than a struct.
- [Bill] Pairs and tuples…are useful in places…where you want to carry multiple, strongly typed values.…In many cases, a pair or a tuple…can be more convenient than a struct.…Here, I have a working copy of pair.cpp…from chapter two of the exercise files.…The pair type is in the utility header.…It's a small and simple type…that's useful for carrying a pair of strongly typed values.…There are several constructors available for pair,…and we can scroll down here…and we can see the pair being constructed…with an initializer list,…which is available, of course, beginning in C++11.…
A pair being instructed with a default constructor…and the values being passed directly,…and a pair being constructed with make_pair,…and there's also comparison operators available.…When I build and run this,…you'll see we have our initialized pairs…and we have the comparison operator results.…The comparison operator…does compare both values of the pair,…but it gives priority to the first value.…So, if the first values create…a comparison that's not equal,…
- Template fundamentals
- STL containers
- Accessing iterators
- Output, forward, and bidirectional iterators
- The transform function
- Transforming strings and types
- Arithmetic, relational, and logical functions
- STL algorithms
Skill Level Intermediate
2. STL Containers
3. STL Iterators
5. STL Functions
6. STL Algorithm
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.