โ† All CPP Flashcard Decks

Modern C++ Features (C++17/20) Flashcards

7 cards from real CPP practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 7 Modern C++ Features (C++17/20) flashcards as text
  1. What does the C++17 structured binding `auto [x, y] = std::make_pair(1, 2.0);` deduce for `x` and `y`?

    Answer: x is int, y is double

    Structured bindings decompose the pair preserving each element's original type, so x is int and y is double.

  2. Which C++17 feature allows `if (auto it = map.find(key); it != map.end())` syntax?

    Answer: If statement with initializer

    C++17 added an optional init-statement to if and switch, scoping the declared variable to the conditional block.

  3. What is the result of the fold expression `(args + ...)` when args is an empty pack?

    Answer: Compilation error for operator+

    Unary fold over + with an empty pack is ill-formed; only &&, ||, and comma operator have identity elements defined for empty packs.

  4. What does `std::optional opt;` evaluate to when used in a boolean context?

    Answer: false, because it holds no value

    A default-constructed std::optional is disengaged, and its bool conversion returns false.

  5. Which C++17 class template deduction guide allows `std::vector v = {1, 2, 3};` without specifying ``?

    Answer: Class Template Argument Deduction (CTAD)

    CTAD lets the compiler deduce template arguments from constructor call arguments, eliminating the need for explicit angle-bracket types.

  6. What guarantee does C++17 provide about the evaluation of `f() + g()` regarding the order of `f` and `g`?

    Answer: No guaranteed order between f() and g()

    C++17 strengthened sequencing rules but still leaves the relative order of operand evaluation for + unspecified.

  7. In C++17, `if constexpr (condition)` differs from regular `if` in that:

    Answer: The discarded branch is not instantiated in templates

    if constexpr discards the non-taken branch at compile time within templates, preventing instantiation of otherwise ill-formed code.