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

[expos.only.func] Should we move decay-copy to [range.adaptors.general] ? #5044

Closed
frederick-vs-ja opened this issue Oct 21, 2021 · 11 comments
Closed

Comments

@frederick-vs-ja
Copy link
Contributor

frederick-vs-ja commented Oct 21, 2021

After adopting P0849R8 and P2321R2 (with some editorial changes), only range adaptor objects views::all, views::take, and views::drop are still specified via decay-copy. So perhaps it's OK to move decay-copy to [range.adaptors.general].

@jwakely
Copy link
Member

jwakely commented Oct 21, 2021

If we do add another use for it outside that clause we'd need to move it back again, so I'm not sure it's worth it.

@tkoeppe
Copy link
Contributor

tkoeppe commented Oct 21, 2021

Can't we just replace uses of decay-copy with the new auto?

@jensmaurer
Copy link
Member

Yes, that's what the "auto" paper did in the places where it is applicable. However, decay-copy and auto have some subtle difference, and the remaining uses are not obviously auto-able.

@tkoeppe
Copy link
Contributor

tkoeppe commented Oct 21, 2021

What are the differences? "auto" was pitched as "decay-copy in the language"...?

@jensmaurer
Copy link
Member

I think "auto" doesn't materialize temporaries per se (it just passes through an rvalue argument as an rvalue, thanks to "guaranteed copy elision"), whereas decay-copy always materializes a temporary from an rvalue, because it's pitched as a "real" function.

@tkoeppe
Copy link
Contributor

tkoeppe commented Oct 21, 2021

Oh, that's subtle -- thanks! Does that make a difference in the library?

@jwakely
Copy link
Member

jwakely commented Oct 21, 2021

Yes, which is why LWG asked for changes to P0849 so that it didn't replace all uses.

@tkoeppe
Copy link
Contributor

tkoeppe commented Oct 21, 2021

@tkoeppe
Copy link
Contributor

tkoeppe commented Oct 21, 2021

What about std::move(auto(x))?

@frederick-vs-ja
Copy link
Contributor Author

std::move(auto(x)) can't be used, because it's an xvalue, while RAOs always return prvalues.

I think the uses of decay-copy in views::take and views::drop are doubtful. Apparently ((void) F, (void) E, T()) may be used instead, which means they return a default-constructed empty_view in those cases. However, it's not guaranteed that copy/move of an empty_view has no side effects, especially for program-defined specializations.

@jensmaurer
Copy link
Member

I think we've established that auto and decay-copy are not identical, so replacing one for the other could be changing semantics. Any such change would thus need an LWG issue.

There is also little support for moving the definition of decay-copy.

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

4 participants