Skip to content

Cleanups: Avoid almost always auto - #3530

Merged
Stephan T. Lavavej (StephanTLavavej) merged 3 commits into
microsoft:mainfrom
StephanTLavavej:stl-cleanups-almost-never-auto
Mar 7, 2023
Merged

Cleanups: Avoid almost always auto#3530
Stephan T. Lavavej (StephanTLavavej) merged 3 commits into
microsoft:mainfrom
StephanTLavavej:stl-cleanups-almost-never-auto

Conversation

@StephanTLavavej

Copy link
Copy Markdown
Member

We conventionally avoid the pattern auto variable = Type{args}; because it is strictly more complicated than Type variable{args};. Following this convention reserves auto for the cases where it's doing real work to deduce a type.

We've accumulated a few cases which I'm cleaning up here. (There are a few more cases which I am reluctantly not changing, because auto results in code lining up nicely. I thought about it, though.)

In P2321R2_views_zip, I'm also performing some renames. We can name the parameters single_element_container and three_element_container, as that's relevant to the caller. Then we can rename the local copy to just writable, which avoids wrapping lines.

In <__msvc_int128.hpp>, I'm using static_cast. MSVC emits a signed/unsigned warning if we attempt to directly initialize _Int_max (possibly because numeric_limits::max() is constexpr but not consteval). Since we're intentionally changing the type from int to size_t, it seems stylistically best to emphasize this with a static_cast anyways.

Name the parameters single_element_container and three_element_container,
as that's relevant to the caller. Then we can rename the local copy to
just `writable`, which avoids wrapping lines.
MSVC emits a probably-unjustified signed/unsigned warning if we attempt
to directly initialize _Int_max. Since we're intentionally changing the
type from int to size_t, it seems stylistically best to emphasize this
with a static_cast anyways.
@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) added enhancement Something can be improved ranges C++20/23 ranges labels Mar 3, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still prefer almost always auto in a lot of these cases, but I know that's not the style of the standard library, so approve.

@StephanTLavavej

Copy link
Copy Markdown
Member Author

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej
Stephan T. Lavavej (StephanTLavavej) merged commit e7aa390 into microsoft:main Mar 7, 2023
@StephanTLavavej
Stephan T. Lavavej (StephanTLavavej) deleted the stl-cleanups-almost-never-auto branch March 7, 2023 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Something can be improved ranges C++20/23 ranges

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants