Šimon Tóth’s Post

View profile for Šimon Tóth

C++ Educational Content Creator | 20 years of Software Engineering experience distilled into digestible daily posts

Since C++26, we can finally avoid the cumbersome need to name objects even when the name doesn't matter using the placeholder name _. For variables with dynamic lifetimes, non-static members, lambda captures and structured bindings, the _ can redefine existing instances in the same scope. If the _ has a unique meaning (no redefinition), it can still be referenced. Compiler Explorer link: https://lnkd.in/erpS3Tw7 #cpp #cplusplus #coding #programming #dailybiteofcpp

  • text

In the Mutex example, If I don’t the variable name , why do I need to define it, we can use them as a call function?

Like
Reply

That’s great! What it would be the behavior before C++26? Can the compiler optimize even if there are side effects?

Like
Reply

Is it April 1st? This is atrocious (readability reasons).

Doesn’t look very appealing to me. It will make the code less readable and more difficult to maintain. Imho it’s always better to have code as explicit as possible so the coder doesn’t have to ask himself too many questions to understand what he’s looking at. And it should also be considered that readability is very important to smooth out the variable skill level and experience in large teams and projects

Why? Why the _ are we doing this?

I don't like this solution to the RAII only objects. I think having a mechanism to defer the destruction of such objects until the end of the scope would be better, instead of how they behave now. std::unique_lock{mux}; acquires the lock but also immediately releases it due to the dtor getting called. Wouldn't deferring the dtor be better, and cleaner?

Like
Reply

Why does C++ seem to be inching closer to Python in terms of syntax? Is it an acknowledgment of the growing preference for more readable and succinct code among developers, or perhaps a nod to the increasing importance of cross-language interoperability?

You can use _ in older versions too, just not within the same context.

Like
Reply

Now I am not sure about C++ anymore. I simply can't recognize the language anymore.

See more comments

To view or add a comment, sign in

Explore content categories