Skip to content

style: convention for optional reference wrapper type alias#9725

Merged
junr03 merged 7 commits intoenvoyproxy:masterfrom
junr03:opt-ref
Jan 28, 2020
Merged

style: convention for optional reference wrapper type alias#9725
junr03 merged 7 commits intoenvoyproxy:masterfrom
junr03:opt-ref

Conversation

@junr03
Copy link
Copy Markdown
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
Copy Markdown
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>
* 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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