r/cpp • • May 03 '26

The Most Confusing C++ Behavior

https://codestyleandtaste.com/most-confusing-C++-behavior.html
37 Upvotes

51 comments sorted by

View all comments

Show parent comment

1

u/EdwinYZW May 04 '26

const auto val = 10;

This guarantees no implicit conversion.

3

u/levodelellis May 04 '26

No, that's not true, that's impossible

3

u/EdwinYZW May 04 '26

What is not true?

2

u/levodelellis May 04 '26

Today is May 4th, a day where people will post star wars memes, jokes and quotes

I was just making a joke. "const auto val = 10;" does not look like a "correct initialization"

3

u/Wild_Meeting1428 May 04 '26

You are an AA guy my friend? So why not east-const instead of const-west :P.
For me, it's always auto const val = 10;

Jokes aside, regarding the branched initialization one could also use lambdas or statement expressions.

auto const val = [expr] { if(expr) return init_true(); return init_false(); }()
Then OP does not need to slide anything through.

4

u/EdwinYZW May 04 '26

Yes. Immediately call a lambda is also a nice trick to make a constant. :D

const-west is more readable for me in normal situations, unless I'm dealing int const. So I would rather use int constint const.