Understanding how to navigate and effectively use programming language documentation is an essential skill for any programmer. The C++ Standard Library provides a variety of pre-built functions and data structures that simplify complex tasks and can improve the efficiency of your code. However, to use these tools effectively, you will need to know how to find and interpret the documentation.
All mature programming languages provide reference documentation to help developers understand the various components and features of the language. Here are a few examples of reference documentation for other programming languages:
Golang(my personal favorite language): pkg.go.dev/fmt#PrintlnPython 3: docs.python.org/3/library/functions.html#printC#: learn.microsoft.com/en-us/dotnet/api/system.console.writeline?view=net-8.0Java: docs.oracle.com/en/java/javase/23/docs/api/java.base/java/io/PrintStream.html#println()
§1 Reading Programming Documentation #
When working with programming languages like C++, it’s essential to recognize the difference between reference documentation and tutorials/guides. Reference documentation provides detailed, technical information on components like functions and classes, with a focus on precise details such as function signatures and performance. It’s ideal for developers who already understand the basics and need specific information.
On the other hand, tutorials and guides explain concepts in a step-by-step manner, making them ideal for beginners or those learning new features. They focus on how and why things work, providing examples and walkthroughs. Both types of documentation serve important but distinct roles in the development process.
§1.1 How to Effectively Read C++ Documentation #
- Start with the Overview: Read the component’s description (e.g.,
std::vector,std::map) to understand its purpose and use cases. Look up unfamiliar terms as needed. - Identify Key Functions: Skim the list of functions, focusing on commonly used ones. Pay attention to performance (time complexity) and exceptions.
- Understand Function Signatures: Analyze function declarations, parameters, and return types. Understand overloaded functions and template types.
- Check Example Usages: Study code examples in the documentation to see how the component works in practice.
- Look for Performance Information: Review performance details like time complexity to understand the efficiency of operations.
- Understand Edge Cases: Learn about exceptions and limitations (e.g.,
at()vs.operator[]instd::vector). - Search for Terms: Use search functions (such as site search bars or
Ctrl+F) to find specific information quickly. - Stay Curious: Explore how different components interact and consider their broader use.
For C++ code, the following sites are useful sources for reference documentation on the standard library:
Example: Reference documentation page for std::vector:
cppreference.com vector | cplusplus.com vector
§2 Assignment #
You will use both cplusplus.com and cppreference.com to find answers to the following questions. Both sites offer relevant information, but depending on the information you are seeking, one source might be more useful than the other. All of the information you will need for this assignment can be found on these sites.
- What is the difference between
push_back()andemplace_back()in astd::vector? When should you use one over the other?
- Explain the difference between
at()and theoperator[]in accessing elements of astd::vector. When would you prefer one over the other?
- What is the time complexity of
std::vector::insert()when inserting in the middle of the vector?
- Can
std::mapstore duplicate keys?
- What is the difference between
std::mapandstd::unordered_mapin terms of internal structure? Which is more performant?
- What does
std::list::splice()do? Doesstd::list::splice()copy any data?
- What are the minimum and maximum number of parameters that can be passed to
std::list::splice()in C++23?
- What is the default sorting order of elements in
std::set? Can the sorting order be overridden?
- Explain the purpose of
std::mutex.
- What is the earliest version of C++ that supports
std::chrono::time_zone?
- List all of the direct member functions of
std::chrono::steady_clock.
- Approximately how many functions are available in the
<algorithm>library?
- What does
std::for_each()do in the<algorithm>library?
- What does
std::string::erase()do? Does this function copy the string?
- What does the
std::anytype represent? Provide a simple code snippet demonstrating how it can be used.
ChatGPT and other AI models hallucinate some extremely bad answers to some of these questions. AI chatbots can be incredibly helpful to ask questions and understand concepts, but are not a replacement for actually looking at the reference documentation.
AI may answer some of these questions very incorrectly.
Any obviously wrong AI answers will result in an automatic −50% for your grade on this assignment.