Skip to content

Use universal references in append() method #1067

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

Closed
wants to merge 2 commits into from

Conversation

dota17
Copy link
Member

@dota17 dota17 commented Oct 24, 2019

This litte patch fixes issue #1046.

@BillyDonahue
Copy link
Contributor

BillyDonahue commented Nov 3, 2019

This is not a "universal reference" (which are now called "forwarding references").
It's an rvalue reference.

Anyway, for an "append" member function I'm looking at copying the API of standard container members like vector::push_back, which will always have a const T& and a T&& overload.

The Microsoft.co.il blog referred to in #1046 is having an internal problem right now so I can't read it, but I haven't heard of the {const T&, T&&} overload set as being a problem for append methods before.

I was able to find a mirror of it. ( https://dzone.com/articles/c-sink-parameter-passing ).

We're in the "write two overloads" camp currently, about which the author says:

""" The “only” problem with two overloads is that this approach doesn’t scale for multiple parameters."""

Well all we have are the ArrayIndex and the Value, and the ArrayIndex is an int.
The Value is the thing that needs to be treated specially, and that's what we're doing.
I think it's fine as-is, and we have a solution that doesn't require unnecessary moves of Value.

@BillyDonahue
Copy link
Contributor

@dota17 can we close this PR now?

@dota17
Copy link
Member Author

dota17 commented Nov 12, 2019

@dota17 can we close this PR now?

@BillyDonahue
if we close this PR, then how can we treat this issue #1046?
and how about the insert method?

@BillyDonahue
Copy link
Contributor

@dota17 you are right. We should get a consensus on #1046 before closing this.

@dota17
Copy link
Member Author

dota17 commented Nov 15, 2019

Closing. See the discussions in #1046.

@dota17 dota17 closed this Nov 15, 2019
@cdunn2001
Copy link
Contributor

I hope Billy and Jordan don't feel as if they've wasted their own time on this. Personally, this was very informative for me, including the experiments. So I'm glad you tried this, Chen.

@dota17
Copy link
Member Author

dota17 commented Nov 15, 2019

I hope Billy and Jordan don't feel as if they've wasted their own time on this. Personally, this was very informative for me, including the experiments. So I'm glad you tried this, Chen.

Yes, I agree, the experiments for this issue are very important. Thanks to Billy and Jordan's experiments. we have a clear and and reliable conclusions for that now.

@dota17 dota17 deleted the pass-by-value branch January 13, 2020 07:58
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