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

Iterator::collect should ideally support conversions #425 #451

Closed
wants to merge 1 commit into from

Conversation

Ananyasingh2002
Copy link

Resolved the issue#425 with collecting Iterator<const std::string&> into Vecstd::string. Implemented map(|s| s.to_owned()) to convert constant references in the iterator to owned std::strings. This transformation rectified the mismatch, allowing successful collection into Vecstd::string. The adjustment eliminates the need for .cloned() and ensures compatibility with the copy constructible type.

Copy link

google-cla bot commented Jan 1, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@Neilblaze
Copy link

@Ananyasingh2002 you need to sign the CLA first to make the workflow run.

@Ananyasingh2002
Copy link
Author

Ananyasingh2002 commented Jan 1, 2024

Hello @Neilblaze, It seems there's an issue preventing me from signing the Contributor License Agreement (CLA). The message indicates a server error, advising me to retry the request.

@danakj
Copy link
Collaborator

danakj commented Jan 5, 2024

I am a bit confused about this PR. It seems to be assuming the collect function is doing conversion already?

The issue is that IntoIterator (and thus collect) requires the into_iter() function's returned Iterator::Item type to be exactly the same as the type specified in IntoIterator. But I believe it would be better here to match an Iterator::Item type if its convertible-to the type in IntoIterator.

Some options:

  • Maybe collect needs to use a more lenient version of IntoIterator, and perform a map itself when the types don't match.
  • Maybe Iterator can match a concrete type if its Item is convertible-to T since next() returning a T will be valid in code that wants something T converts to as well.

I will copy these thoughts to the issue.

@danakj
Copy link
Collaborator

danakj commented Feb 20, 2024

Haven't heard anything in a bit here, will you be coming back to it?

@danakj danakj closed this May 22, 2024
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.

4 participants