-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Change T.46 to not require copyability, and to account for traits types (see #2281) #2320
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
Open
hsutter
wants to merge
1
commit into
master
Choose a base branch
from
Update-T.46
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+6
−5
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17074,7 +17074,7 @@ Template interface rule summary: | |
| * [T.42: Use template aliases to simplify notation and hide implementation details](#rt-alias) | ||
| * [T.43: Prefer `using` over `typedef` for defining aliases](#rt-using) | ||
| * [T.44: Use function templates to deduce class template argument types (where feasible)](#rt-deduce) | ||
| * [T.46: Require template arguments to be at least semiregular](#rt-regular) | ||
| * [T.46: Prefer template arguments to be movable and default-constructible](#rt-regular) | ||
| * [T.47: Avoid highly visible unconstrained templates with common names](#rt-visible) | ||
| * [T.48: If your compiler does not support concepts, fake them with `enable_if`](#rt-concept-def) | ||
| * [T.49: Where possible, avoid type-erasure](#rt-erasure) | ||
|
|
@@ -18110,7 +18110,7 @@ For example: | |
|
|
||
| Flag uses where an explicitly specialized type exactly matches the types of the arguments used. | ||
|
|
||
| ### <a name="rt-regular"></a>T.46: Require template arguments to be at least semiregular | ||
| ### <a name="rt-regular"></a>T.46: Prefer template arguments to be movable and default-constructible | ||
|
|
||
| ##### Reason | ||
|
|
||
|
|
@@ -18120,6 +18120,7 @@ Most uses support that anyway. | |
|
|
||
| ##### Example | ||
|
|
||
| // X is not default constructible | ||
| class X { | ||
| public: | ||
| explicit X(int); | ||
|
|
@@ -18135,13 +18136,13 @@ Most uses support that anyway. | |
| X y = x; // fine | ||
| std::vector<X> v(10); // error: no default constructor | ||
|
|
||
| ##### Note | ||
| ##### Exceptions | ||
|
|
||
| Semiregular requires default constructible. | ||
| A trait type is not necessarily movable and default-constructible. Templates that use trait types usually use them with `Trait::something` scope resolution syntax, rather than using objects of the trait type. | ||
|
|
||
| ##### Enforcement | ||
|
|
||
| * Flag types used as template arguments that are not at least semiregular. | ||
| * Flag types used as template arguments that do not satisfy both `std::movable` and `std::default_constructible` and that are using in the template without `::` scope resolution syntax. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be "that are used" not "that are using", but I think the change just needs to be rewritten anyway. |
||
|
|
||
| ### <a name="rt-visible"></a>T.47: Avoid highly visible unconstrained templates with common names | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is true, all standard trait types are movable and default constructible, and you probably want them to be so that you can use them for tag dispatching.
OK, this is true, but irrelevant.
I don't think the issue is saying that trait types themselves are not movable and therefore we need an exception for trait types. I think it's saying that using non-movable types as the template arguments of traits violates the guideline. But of course we want to be able to use
std::is_move_assignable_v<X>andis_default_constructible_v<X>even if X is not movable or not default constructible.So I think this change misses the mark.
I think if you want to keep the rule then you should do something like make an exception for templates which do not actually construct the type, e.g. type traits which are purely compile-time queries for properties of a type and do not have any side effects.
The case of
unique_ptr<X>requires a different exception. That certainly does do things with an object of typeXbut there is no reason whatsoever that it needs X to be semiregular. It never makes a new object of typeX, and usingunique_ptrto manage non-movable objects on the heap is a perfectly valid thing to do.