logoalt Hacker News

on_the_trainyesterday at 2:22 PM3 repliesview on HN

There is in c++, too (std::ignore). Not sure why the author decided to go with the ancient void cast


Replies

quuxplusonetoday at 5:02 AM

https://quuxplusone.github.io/blog/2022/10/16/prefer-core-ov... does not (yet) include this as one of its examples, but it could (and someday might).

vitusyesterday at 5:43 PM

std::ignore's behavior outside of use with std::tie is not specified in any finalized standard.

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p29... aims to address that, but that won't be included until C++26 (which also includes _ as a sibling commenter mentions).

aw1621107yesterday at 4:29 PM

I believe C++26 now allows _ as a placeholder name [0]:

> We propose that when_ is used as the identifier for the declaration of a variable, non static class member variable, lambda capture or structured binding. the introduced name is implicitly given the [[maybe_unused]] attribute.

> In contexts where the grammar expects a pattern matching pattern,_ represents the wildcard pattern.

Some of the finer details (e.g., effect on lifetime and whether a _ variable can be used) differ, though.

[0]: https://github.com/cplusplus/papers/issues/878

show 1 reply