MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/cpp/comments/1t2xmw4/the_most_confusing_c_behavior/ojtynoc/?context=3
r/cpp • u/levodelellis • May 03 '26
51 comments sorted by
View all comments
Show parent comment
1
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 quotesI 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. :Dconst-west is more readable for me in normal situations, unless I'm dealing int const. So I would rather use int constint const.
3
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 quotesI was just making a joke. "const auto val = 10;" does not look like a "correct initialization"
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 quotesI was just making a joke. "const auto val = 10;" does not look like a "correct initialization"
2
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"
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;
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.
auto const val = [expr] { if(expr) return init_true(); return init_false(); }()
4 u/EdwinYZW May 04 '26 Yes. Immediately call a lambda is also a nice trick to make a constant. :Dconst-west is more readable for me in normal situations, unless I'm dealing int const. So I would rather use int constint const.
4
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.
View all comments
Show parent comment
1
u/EdwinYZW May 04 '26
const auto val = 10;
This guarantees no implicit conversion.