342.md

August 13, 2023 ยท View on GitHub

Info

Example

auto foo() { return 42; }

int main() {
    auto unused = foo(); // warning in C++23
    auto _ = foo();      // no warning in C++26
}

https://godbolt.org/z/5sY6zs9Yh

Puzzle

  • Can you apply 'A nice placeholder with no name` to the following C++ constructions?

    • guard
    • structure bindings
    • assert
    • NTTP
// TODO: guard
// TODO: structure bindings
// TODO: assert
// TODO: NTTP

https://godbolt.org/z/1xsqhr93z

Solutions

auto guard() {
    std::mutex m;
    std::lock_guard _{m};
    // ...
}

auto structure_bindigns() {
    auto [a, _, c] = std::tuple{1, 2, 3};
    (void)a;
    (void)c;
}

auto assert_() {
    auto _ = 42;
    assert(_ == 42);
}

template<auto _> auto nttp() {}

https://godbolt.org/z/dx9691YKn