Useful C++ Classes

NOTE: this website is out of date. This is the course web site from a past quarter, Fall 2023. If you are a current student taking the course, you should visit the current class web site instead. If the current website is not yet visible by going to cs111.stanford.edu, it may be accessible by visiting this link until the new page is mounted at this address. Please be advised that courses' policies change with each new quarter and instructor, and any information on this out-of-date page may not apply to you.

Handout by John Ousterhout, with modifications by Nick Troccoli

This page lists several classes from the C++ library that you may find useful at some point during CS 111. There are two popular Web sites for learning more about C++ classes: cppreference.com and cplusplus.com. The cppreference.com site is more precise and formal; it tends to be preferred by purists and experts. However, many people find cplusplus.com to be simpler and easier to understand, especially for people still learning C++. We provide links to both sites below; take your pick.

std::condition_variable_any

Used in conjunction with std::mutex or std::unique_lock to put threads to sleep and wake them up again.

[cplusplus] [cppreference]

std::deque

A double-ended queue of objects of arbitrary type. Can insert and remove from both ends.

[cplusplus] [cppreference]

std::function

A variable type that represents a function; you can use it to store functions in variables, pass functions as parameters, etc. and call the function later.

[cplusplus] [cppreference]

std::map

A container that contains key-value pairs where there is an ordering among the keys. Supports both lookup by individual key and also range queries (find a group of objects in order of their keys). This class isn't quite as fast as std::unordered_map, but it supports ordering, which is not supported in std::unordered_map.

[cplusplus] [cppreference]

std::mutex

Standard locks; normally used in conjunction with std::unique_lock.

[cplusplus] [cppreference]

std::queue

FIFO container for objects of any type. Most people find std::deque easier to use and more powerful.

[cplusplus] [cppreference]

std::string

Provides a variety of mechanisms for manipulating strings of text.

[cplusplus] [cppreference]

std::thread

Create system threads.

[cplusplus] [cppreference]

std::unique_lock

Acquires an std::mutex when constructed, automatically unlocks the mutex when the std::unique_lock is destroyed. This class is very useful to ensure that mutexes are always unlocked (e.g. when a method returns).

[cplusplus] [cppreference]

std::unordered_map

A container that contains key-value pairs with unique keys. Both keys and values can have arbitrary type. Provides fast lookup based on keys. The container is unsorted (there is no ordering among the elements)

[cplusplus] [cppreference]

std::vector

Expandable arrays of objects of any type. Provides fast access to any element using its index.

[cplusplus] [cppreference]