-
Notifications
You must be signed in to change notification settings - Fork 769
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
"explicit constexpr" vs. "constexpr explicit" #2371
Comments
I prefer "explicit" to be first. "constexpr" is still semantically the odd one because in some cases (variables) it affects the type (though never when combined with "explicit"). I therefore like to make it the last non-type-specifier before any type specifiers. |
I also prefer "explicit" to be first; the fact that a function can be called in a constant expression is not as much a part of the interface as whether or not the function would be called implicitly. |
Another point: now we have conditional explicit, which is more readable:
... or ...
? I prefer the latter. We should also consider what the correct relative order of Proposed ordering:
OK? |
I'd switch 2 and 3. (And "Boo" on 4. ;-) (But since 4 is the state of reality, I think it makes extra sense for "constexpr" to be just before that.) |
I think 2 vs 3 only comes up for global variables (everywhere else the
versus
I think I agree, the former is better. |
I've updated the wiki with the style rule: @CaseyCarter Anything else you need to put together the pull request? |
I prefer the order
I strongly prefer to see That said, I can happily use this style in my own codebase regardless of whether the Standard ever agrees with me. 🙂 (EDIT to add: I hadn't thought of |
That's a really good point. Especially for conversion functions, So, I'm happy with the proposed change (move |
I have never had the need to specifically grep for conversion operators that are explicit. Where conversion operators (or constructors) are grouped together (which is good practice), being able to quickly gloss past unconditionally explicit candidates has been useful. Having explicit first helps there. Even with conditionally explicit candidates, being able to easily tell that a group of conditions are the same (or more generally, how they are related) would also be helpful. |
Does this also imply that you would group all |
First of all, I'd always use WG14 N1570
For semantic similarity reasons, I feel no particular reasons to order other specifiers. But for consistency, I used to separate and order them in 2 groups in my code:
The second group is concerned with ODR. (BTW, A minor problem is Clang++ complains about Once the grouping order is fixed, either order looks good to me, though I now agree @zygoloid What about #119? (The title is exactly the same, XD) |
Agreed, but I'd hope this situation never arises in the standard library :)
Well, GCC's
I'm coming around to the idea that |
Editorial meeting: See list by @zygoloid, function-specifier (such as a explicit) comes after constexpr, but virtual is early. See wiki page "guidelines", which was updated. |
… explicit" Per discussion in cplusplus#2371.
…xplicit" Per discussion in cplusplus#2371.
$ grep "explicit constexpr" *.tex |
We now have both usages in various standard library components.
Which specifier should come first? In years gone by, it made sense for
constexpr
- the "weird new" specifier - to be first. Now that everything isconstexpr
, it seems to be thatexplicit
is actually the "weird/uncommon" specifier and it should be uniformly first.I'll submit a PR for whichever style people prefer, it's more important to me that we be consistent than that we use my preferred style.
The text was updated successfully, but these errors were encountered: