4 ms·
it's not that weird to explicitly limit the scope of certain variables that logically belong together. But i agree the C++ if(init;cond) thing was new to me.
by i_am_a_peasant 2y ago
it's not that weird to explicitly limit the scope of certain variables that logically belong together.
But i agree the C++ if(init;cond) thing was new to me.
- maccard 2y agoLike everything in C++, it has it's share of footguns if (Foo* f = GetPtr(); f->HasValue()) {} // wrong; f can be null vs if (Foo* f = GetPtr(); f && f->HasValue()){} Is probably the biggest pitfall. Especially if you're used to this: if (Foo* f = GetPtr()) { f->DoTheThing(); // this is perfectly safe. }