Sections[lib]

Standard Library

The library that ships with every compiler, from containers and algorithms to ranges and smart pointers, for developers choosing which type to reach for first.

Clause
2 of 8
Answers
34, newest first
Page
4 of 4
Written for
C++17, C++20, C++23
Written by

Answers in Standard Library 34, newest first

  1. std::optional in C++: how to use it and when not to

    Create, test, read, empty and refill a std::optional, what each accessor does when it is empty, what it costs, and when std::expected fits better.

    §2.611 min readC++17

    written for C++17

  2. std::println in C++23: print without std::cout or printf

    std::println in C++23: the syntax, each std::cout and printf line translated, what a bad format string does, whether it flushes, and std::endl vs newline.

    §2.714 min readC++23

    written for C++23

  3. std::span in C++20: pass a view, not a pointer and a size

    Take std::span by value: what converts to it, slicing with subspan, what s[i] out of range does on each library, and how a span dangles.

    §2.810 min readC++20

    written for C++20

  4. std::variant in C++: std::visit, std::get and the traps

    Create a std::variant, read it with std::get, get_if or std::visit, catch the missing case a conversion hides, and see what it costs and when to skip it.

    §2.99 min readC++17

    written for C++17