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

How to specify small nested classes: struct/class, private members #5323

Open
tkoeppe opened this issue Feb 24, 2022 · 6 comments
Open

How to specify small nested classes: struct/class, private members #5323

tkoeppe opened this issue Feb 24, 2022 · 6 comments

Comments

@tkoeppe
Copy link
Contributor

tkoeppe commented Feb 24, 2022

We have a number of small, nested classes, mainly in the ranges library, which we currently variably specify with class and struct (e.g. outer-iterator, value_type). It might be helpful to pick one class key for all those cases.

A related question is how we order exposition-only members: previously, they used to appear at the end of the class defintion, but the ranges additions have started placing them at the beginning. We should discuss whether we want to mandate any particular style, or if there's value in allowing discretion.

Finally, this is related to the discussion of how to style exposition-only members (#4702).

@tkoeppe
Copy link
Contributor Author

tkoeppe commented Feb 24, 2022

@jwakely, @CaseyCarter: LWG perspectives welcome!

@tkoeppe tkoeppe added the decision-required A decision of the editorial group (or the Project Editor) is required. label Feb 24, 2022
@tkoeppe
Copy link
Contributor Author

tkoeppe commented Feb 24, 2022

Tentatively, what would the rule for using struct be?

  • not having private members
  • being an aggregate
  • not having (non-special) member functions
  • ...?

@CaseyCarter
Copy link
Contributor

There are a ton of structs in Ranges, which I think is a consequence of the fact that Eric Niebler and I both prefer struct to class in our personal styles, and not the result of any explicit particular style choice on the part of LEWG or LWG. We wrote struct because that's what the implementations said, and nobody ever thought it important enough to ask me to change it.

I think Library generally uses the rule that structs have no private data members whereas classes have at least one and maintain invariants, but I wouldn't be surprised if Ranges wasn't the only violator of this rule.

@jensmaurer
Copy link
Member

"No private members" is certainly a good first step. For purposes of the standard, some classes don't have any visible members, but they are containers or so and thus must have data members; they're just not shown. Those should be "class" as well.

@tkoeppe
Copy link
Contributor Author

tkoeppe commented Nov 8, 2022

Editorial meeting opinion: This is not overly important, but we can certainly create and write down a rule. Based on the above, it should be something like "If it has invariants, it's a class, otherwise a struct".

@tkoeppe
Copy link
Contributor Author

tkoeppe commented Nov 8, 2022

Added a wiki entry that recomends the above rule. No further action at this point, though cleanup PRs are welcome.

@tkoeppe tkoeppe removed the decision-required A decision of the editorial group (or the Project Editor) is required. label Nov 8, 2022
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

No branches or pull requests

3 participants