{
std::unique_ptr<T> x = foo();
if(x->something()) {
// use x
}
}
// x out of scope, destructed
becomes if(auto x = foo(); x->something()) {
// use x
}
// x out of scope, destructed
It's makes it easier to read the lifetime of x (an important thing you have to manually keep an eye on in C++ in many cases), and to determine what is in scope outside of the if statement. It's analogous to for-loops vs. doing loops "manually" with while. You're just used to for-loops by this point (if you don't like for loops then ok :).)C# is also getting (has got?) this feature.