C++ STL (Standard Template Library) is a powerful library that provides a set of generic algorithms, containers, and iterators for C++ programming language. It was introduced in the C++98 standard and has been an integral part of the language ever since.
The STL is designed to provide a high level of abstraction, allowing developers to write efficient and reusable code. It includes a wide range of containers such as vectors, lists, maps, sets, and more. These containers are designed to store and manipulate data efficiently, and they provide a range of operations such as insertion, deletion, and searching.
The algorithms provided by the STL are also highly efficient and can be used with any container. They include sorting, searching, and manipulating algorithms, among others. These algorithms are designed to work with iterators, which are used to traverse the elements of a container.
One of the key benefits of using the STL is that it provides a consistent and standardized interface for working with containers and algorithms. This makes it easier for developers to write code that is portable and can be used across different platforms and compilers.
Overall, the C++ STL is a powerful library that provides a range of containers, algorithms, and iterators for C++ programming. It is widely used in industry and academia and is an essential tool for any C++ developer.
Containers
Name | Description |
---|---|
std::vector | A dynamic array that can be resized at runtime. |
std::list | A doubly linked list. |
std::deque | A double-ended queue. |
std::set | A sorted set of unique elements. |
std::map | A sorted map of key-value pairs. |
std::unordered_set | An unordered set of unique elements. |
std::unordered_map | An unordered map of key-value pairs. |
Iterators
Name | Description |
---|---|
std::begin | Returns an iterator to the beginning of a container. |
std::end | Returns an iterator to the end of a container. |
std::advance | Advances an iterator by a specified number of positions. |
std::distance | Returns the distance between two iterators. |
Algorithms
Name | Description |
---|---|
std::sort | Sorts a range of elements. |
std::find | Finds the first occurrence of a value in a range. |
std::count | Counts the number of occurrences of a value in a range. |
std::transform | Applies a function to a range of elements and stores the result in another range. |
std::accumulate | Computes the sum of a range of elements. |
Strings
Name | Description |
---|---|
std::string | A string class that can be resized at runtime. |
std::getline | Reads a line of input from a stream. |
std::stoi | Converts a string to an integer. |
std::stod | Converts a string to a double. |
std::to_string | Converts a value to a string. |
Memory Management
Name | Description |
---|---|
std::unique_ptr | A smart pointer that owns and manages a dynamically allocated object. |
std::shared_ptr | A smart pointer that allows multiple pointers to share ownership of an object. |
std::make_unique | Creates a new std::unique_ptr with a dynamically allocated object. |
std::make_shared | Creates a new std::shared_ptr with a dynamically allocated object. |
Miscellaneous
Name | Description |
---|---|
std::pair | A class that holds two values of different types. |
std::tuple | A class that holds multiple values of different types. |
std::chrono | A library for working with time and dates. |
std::random_device | A class for generating random numbers. |
std::thread | A class for creating and managing threads. |
Conclusion
This cheat sheet provides a quick reference for the most commonly used C++ STL functions and classes. However, it is not an exhaustive list, and there are many other functions and classes available in the STL. For more information, consult the C++ documentation or a comprehensive C++ reference book.
Reference:
https://learn.microsoft.com/en-us/cpp/standard-library/cpp-standard-library-reference?view=msvc-170