Re: Coding style for C++ constructs going forward
David Blaikie via Gdb <[email protected]>
| Newsgroups | gmane.comp.gdb.devel,gmane.comp.gcc.devel |
|---|---|
| Message-ID | <CAENS6EtjVkm3Y1RbuzaFzp1YL_KajG8jUHJCrnv8VTRQ_V3Bag@mail.gmail.com> |
On Tue, Aug 11, 2020 at 7:49 PM Liu Hao via Gdb <[email protected]> wrote: > > 在 2020/8/11 下午9:55, Nathan Sidwell 写道: > > > > I agree, it's the way I use auto. I particularly like the > > auto *foo = expr; > > idiom, when you're getting a pointer, but the type of the pointee is clear. It informs how you use 'foo'. > > > > > > Personally I dislike this syntax. Pointers are objects, and `auto foo = expr;` should suffice. What if the type of `expr` is > `unique_ptr<T>` or `optional<T>`? The ptr-operator just can't exist there. So why the differentiation? > > `auto& foo = ...` and `const auto& foo = ...` are necessary to indicate that the entity being declared is a reference (and > is not an object), while `auto*` doesn't make much sense, as I discourage plain pointers in my projects. Then use of `auto*` would make it easier for you to spot use of plain pointers in your projects & scrutinize them further? > > > > -- > Best regards, > LH_Mouse >