Skip to content

Introduction to C++ Standard Library

C++ Standards

First, it is necessary to introduce the versions of C++ itself. Since C++ is merely a language, and different compilers implement C++ in varying ways, standardization is required to constrain compiler implementations, ensuring consistent behavior of C++ code across different compilers. Since its inception in 1985, the International Organization for Standardization (ISO) has released five official C++ standards: C++98, C++03, C++11 (also known as C++0x), C++14 (also known as C++1y), C++17 (also known as C++1z), and C++20 (also known as C++2a). The C++ standard drafts are available on the open-std website, with the latest standard C++23 (also known as C++2b) still under development. Additionally, there are supplementary standards, such as C++ TR1.

Each version of the C++ standard not only specifies the syntax and language features of C++ but also defines the implementation specifications for a set of built-in libraries, known as the C++ Standard Library. The C++ Standard Library contains implementations of a large number of commonly used functionalities, such as input/output, basic data structures, memory management, and multithreading support. Mastering the C++ Standard Library is an essential step in writing more modern C++ code. Detailed documentation for the C++ Standard Library is available on the cppreference website, which provides explanations of the usage, efficiency, and considerations for types and functions in the standard library. Please make good use of it.

It should be noted that different OJ platforms support different C++ versions. For example, the latest ICPC competition rules support the C++20 standard. According to the decision of the NOI Scientific Committee, starting from September 1, 2021, NOI Linux 2.0 has been used as the standard environment for NOI series competitions and activities such as CSP-J/S. The g++ 9.3.0 specified in NOI Linux 2.0 defaults to supporting the C++14 standard and also supports the C++17 standard, meeting the needs of most competitive programming participants. Therefore, when learning C++, it is important to pay attention to the standards supported by competitions to avoid compilation errors during contests.

Standard Template Library (STL)

STL, the Standard Template Library, is part of the C++ Standard Library and includes templated general-purpose data structures and algorithms. Due to its templated nature, it can be compatible with custom data types, avoiding the need to reinvent the wheel. Both NOI and ICPC competitions support the use of the STL library, so leveraging STL appropriately can eliminate the need to write redundant algorithms and fully utilize compiler optimizations for template libraries to improve efficiency. For detailed information on the STL library, please refer to the corresponding pages: STL Containers and STL Algorithms.

What is Reinventing the Wheel

Reinventing the wheel (Reinventing_the_wheel) refers to re-inventing existing algorithms or rewriting already optimized code. Reinventing the wheel is often time-consuming and labor-intensive, and the results may not be as good as existing solutions. However, for learning or practice purposes, reinventing the wheel can be necessary.

Boost Library

Boost is another well-known open-source C++ utility library besides the standard library, known for its portable, high-quality, high-performance, and highly reliable code. The number of modules in Boost is extensive, covering a wide range of functionalities, and it provides comprehensive cross-platform support, making it regarded as a quasi-standard library for C++. Many features in the C++ standard also originate from Boost, such as smart pointers, metaprogramming, date and time, etc. Although Boost cannot be used in OI competitions, many of its components can be used to verify algorithms or for testing, such as Boost.Geometry for R-tree implementations, Boost.Graph for graph-related algorithms, and Boost.Intrusive for a set of intrusive containers similar in usage to STL containers. Interested readers can search for tutorials online.

References

  1. C++ reference
  2. C++ Reference Manual
  3. Wikipedia - C++
  4. Boost Official Website
  5. Boost Tutorial Website