Answers

Newest first. When a later standard changes an answer, the article is updated in place and says what changed and since when.

Each answer names the standard it is written for: 111417202326

Document
Answers
Answers
67, newest first
Page
7 of 7
Written by
Sections
All eight
Feed
RSS
  1. 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.

    Standard Library §2.810 min readC++20

    written for C++20

  2. std::thread and std::jthread: start, join and stop a thread

    Start a thread with std::thread or std::jthread (C++20): pass arguments with std::ref, get a result, stop it with a stop_token, and what a missed join prints.

    Concurrency §5.36 min readC++20

    written for C++20

  3. 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.

    Standard Library §2.99 min readC++17

    written for C++17

  4. std::vector in C++: size, capacity, erase and reallocation

    std::vector size against capacity, how each standard library grows it, what every member invalidates, and erase, find and sort, checked on four compilers.

    Performance §4.215 min readC++17

    written for C++17

  5. C++ try catch: how to throw and catch exceptions

    C++ try, catch and throw: the syntax, why you catch by const reference, the order of handlers, your own exception type, and what happens when nothing catches.

    Language §1.53 min readC++17

    written for C++17

  6. using namespace std: what it does and what to write instead

    What using namespace std does to name lookup, the clashes and silent overload changes it caused on four compilers, and what to write instead.

    Language §1.615 min readC++17

    written for C++17

  7. When to mark a move constructor noexcept in C++

    Mark moves and swap noexcept when they cannot throw, or std::vector copies where it could move. What is noexcept already, and how to check it at compile time.

    Performance §4.312 min readC++20

    written for C++20