Assignment 2: Programming Documentation

Reading C++ Documentation

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:

§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 #

  1. 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.
  2. Identify Key Functions: Skim the list of functions, focusing on commonly used ones. Pay attention to performance (time complexity) and exceptions.
  3. Understand Function Signatures: Analyze function declarations, parameters, and return types. Understand overloaded functions and template types.
  4. Check Example Usages: Study code examples in the documentation to see how the component works in practice.
  5. Look for Performance Information: Review performance details like time complexity to understand the efficiency of operations.
  6. Understand Edge Cases: Learn about exceptions and limitations (e.g., at() vs. operator[] in std::vector).
  7. Search for Terms: Use search functions (such as site search bars or Ctrl+F) to find specific information quickly.
  8. 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.

  1. What is the difference between push_back() and emplace_back() in a std::vector? When should you use one over the other?
  1. Explain the difference between at() and the operator[] in accessing elements of a std::vector. When would you prefer one over the other?
  1. What is the time complexity of std::vector::insert() when inserting in the middle of the vector?
  1. Can std::map store duplicate keys?
  1. What is the difference between std::map and std::unordered_map in terms of internal structure? Which is more performant?
  1. What does std::list::splice() do? Does std::list::splice() copy any data?
  1. What are the minimum and maximum number of parameters that can be passed to std::list::splice() in C++23?
  1. What is the default sorting order of elements in std::set? Can the sorting order be overridden?
  1. Explain the purpose of std::mutex.
  1. What is the earliest version of C++ that supports std::chrono::time_zone?
  1. List all of the direct member functions of std::chrono::steady_clock.
  1. Approximately how many functions are available in the <algorithm> library?
  1. What does std::for_each() do in the <algorithm> library?
  1. What does std::string::erase() do? Does this function copy the string?
  1. What does the std::any type 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.