if(autoitr(character_map.find(c)); itr !=character_map.end()){// *itr is valid. Do something with it.}else{// itr is the end-iterator. Don't dereference.}// itr is not available here at all
// if: before C++17
{
auto var(init_value);
if (condition){
// branch A. var is accessible
} else {
// branch B. var is accessible
}
// var is still accessible
}
// if: since C++17
if (auto var (init_value); condition){
// branch A. var is accessible
} else {
// branch B. var is accessible
}
// var is not accessible any longer
// switch: before C++17
{
auto var (init_value);
switch (var) {
case 1: ...
case 2: ...
...
}
// var is still accessible
}
// switch: since C++17
switch(auto var (init_value); var){
case 1: ...
case 2: ...
...
}
// var is not accessible any longer
if (std::lock_guard<std::mutex> lg {my_mutex}; some_condition) {
// Do something
}
if (auto shared_pointer (weak_pointer.lock()); shared_pointer != nullptr) {
// Yes, the shared object does still exist
} else {
// shared_pointer var is accessible, but a null pointer
}
// shared_pointer is not accessible any longer
if (DWORD exit_code; GetExitCodeProcess(process_handle, &exit_code)) {
std::cout << "Exit code of process was: " << exit_code << '\n';
}
// No useless exit_code variable outside the if-conditional