Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: convention for optional reference wrapper type alias #9725

Merged
merged 7 commits into from
Jan 28, 2020
Merged

style: convention for optional reference wrapper type alias #9725

merged 7 commits into from
Jan 28, 2020

Conversation

junr03
Copy link
Member

@junr03 junr03 commented Jan 17, 2020

Description: noticed in #9516 that we did not have a convention around aliasing absl::optional<std::reference_wrapper<T>>. This PR proposes one.
Risk Level: low. compiles.
Testing: compilation and test suite ran.
Docs Changes: added the convention in STYLE.md

Signed-off-by: Jose Nino jnino@lyft.com

Jose Nino added 2 commits January 17, 2020 13:45
Signed-off-by: Jose Nino <jnino@lyft.com>
fmt
Signed-off-by: Jose Nino <jnino@lyft.com>
@junr03 junr03 requested a review from snowp as a code owner January 17, 2020 22:01
@junr03
Copy link
Member Author

junr03 commented Jan 17, 2020

@jmarantz this is kind of related to #9710. I was chatting with @derekargueta about placing format checking for smart pointer and for this type of aliases. I can create an issue to track if you think it is worth to enforce.

Jose Nino added 2 commits January 17, 2020 14:23
Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: Jose Nino <jnino@lyft.com>
@@ -43,6 +43,9 @@
* `using BarSharedPtr = std::shared_ptr<Bar>;`
* `using BlahConstSharedPtr = std::shared_ptr<const Blah>;`
* Regular pointers (e.g. `int* foo`) should not be type aliased.
* `absl::optional<std::reference_wrapper<T>> is type aliased:
* `using FooOptRef = absl::optional<std::reference_wrapper<T>>;`
* `using FooOptConstRef = absl::optional<std::reference_wrapper<T>>;`
Copy link
Member

Choose a reason for hiding this comment

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

We should probably expand the language on line 41 beyond "smart pointers".

Copy link
Member Author

Choose a reason for hiding this comment

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

@derekargueta not sure what you mean? I see these two as different bullet points.

Copy link
Member

Choose a reason for hiding this comment

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

oh sorry, missed the un-indentation on 46 to make it a new section 👍

jmarantz
jmarantz previously approved these changes Jan 24, 2020
Signed-off-by: Jose Nino <jnino@lyft.com>
using OptionalCounter = absl::optional<std::reference_wrapper<const Counter>>;
using OptionalGauge = absl::optional<std::reference_wrapper<const Gauge>>;
using OptionalHistogram = absl::optional<std::reference_wrapper<const Histogram>>;
using CounterOptRef = absl::optional<std::reference_wrapper<const Counter>>;
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be CounterOptConstRef per your style section?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I should definitely follow my rules 😅. I checked all the other aliases for correctness.

Copy link
Member Author

Choose a reason for hiding this comment

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

Overall I would like the aliases to be CI checked in our formatting run. I will open an issue for that if someone wants to pick up

Copy link
Member Author

Choose a reason for hiding this comment

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

Jose Nino added 2 commits January 27, 2020 11:22
Signed-off-by: Jose Nino <jnino@lyft.com>
fmt
Signed-off-by: Jose Nino <jnino@lyft.com>
@junr03 junr03 merged commit a8d6cb6 into envoyproxy:master Jan 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants