I would like to bring up the a case from creator:

const TextEditor::FontSettings &fontSettings = 
TextEditor::TextEditorSettings::instance()->fontS
ettings();

I really prefer in that case 

const auto &fontSettings = 
TextEditor::TextEditorSettings::instance()->fontSettings();




Should we recommend forward(universal) references in for loops (which are 
"const &value" for "const values"):

for (auto &&value : values)

or

for (const auto &value : values)

to show the difference to

for (auto &value : values)
________________________________________
From: Development <[email protected]> on behalf of Knoll Lars 
<[email protected]>
Sent: Wednesday, December 09, 2015 1:18 PM
To: Giuseppe D'Angelo
Cc: [email protected]
Subject: Re: [Development] RFC: more liberal 'auto' rules?

On 09/12/15 11:19, "Giuseppe D'Angelo" <[email protected]> wrote:



>On Wed, Dec 9, 2015 at 11:16 AM, Knoll Lars <[email protected]> 
>wrote:
>> And I’d say it’s about time to stop that particular sub-thread. It’s neither 
>> productive nor leading anywhere.

Just for the record here, I was only asking to stop the off topic part of the 
discussion (about python and who’s right there). Let’s focus on auto in c++ and 
how we want to use it.

>
>Is there a consensus otherwise about a more liberal use of auto in our
>source code?

I don’t think there is a full consensus. Let me try to summarise where we are, 
what I think we agree upon and then add my thoughts :)

As a primary goal, auto should be used wherever it increases readability of the 
code. I think we all agree here. The problem is that there’s dissent in what 
‘more readable code’ is in practice.

I think everybody also agrees one the use cases listed in 
https://wiki.qt.io/Coding_Conventions#auto_Keyword , so the question now is 
what additional use cases do most of us agree to? And how to put that into 
rules, as a listing with 50 entries won’t help anybody.

While I don’t think we should go and implement aaa right now, I would probably 
be ok with a somewhat broader usage than the current coding conventions imply.

Marc presented some use cases. Going through those, I don’t think I heard any 
disagreement about using auto in template, so I think we can probably add that 
one to our guidelines.

For loop variables, I don’t think we should require ‘auto’. Using it can be the 
right thing to do in some cases, esp when using patterns like ‘for(auto item: 
items)’ , but when looping using integer indices, I still prefer ‘for (int 
i=...; cond; ++i)’.

Are these cases something we can agree upon?

Cheers,
Lars

_______________________________________________
Development mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/development
_______________________________________________
Development mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/development

Reply via email to