342.md
August 13, 2023 ยท View on GitHub
Example
auto foo() { return 42; }
int main() {
auto unused = foo(); // warning in C++23
auto _ = foo(); // no warning in C++26
}
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
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() {}