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
istream_range filtered with take(N) should stop reading at N #57
Comments
Might have to do with this line: https://github.com/ericniebler/range-v3/blob/master/include/range/v3/istream_range.hpp#L63 It does an extraction in the constructor. |
Possible fix. Add a bool to istream_range to determine if the stream is up to date with the current position. |
This might work, but it makes me uncomfortable since a mutating operation is happening in The interaction with the |
IMO the root of this issue is the unexpected interaction of using a view (which shouldn't mutate anything), and the continuously mutating input range. Is there a situation where not incrementing the iterator in One shouldn't need to have a "deeper" understanding of Maybe we should also check other views like |
I'm pretty sure that's the wrong fix. I haven't found a case that breaks yet, but it feels all wrong.
I think it's advanced 6 times. That's not the problem. |
@blindley, regarding https://gist.github.com/blindley/b2e2f9cf18ceade29a77, I think you'll find that your suggested fix still has problems. Tell me what this code does (taking 0 elements instead of 3):
I would expect this code to leave I just don't think there's any good answer here. |
@ericniebler Did you have different results? Or is there something obvious I am missing in my test? |
OK, try this:
For me this prints:
Merely asking the istream range if it's empty is reading an int and throwing it away. |
Okay, I concur. I'll see if that can be fixed. |
I've just noticed that the current version of As of now, the only potential solution that is coming to mind is really nasty. It would involve storing a string buffer in the range to serve as a peek into the |
Right now, I think the best solution is to provide access to the cached value, so that if you stop reading values before the stream runs out, you have a way to get the item that would be lost. That's the best I've come up with. |
Yeah, that's probably much better than what I was thinking. Although I'm curious how it would work (as far as the interface goes), and if you mean to do that instead of, or in addition to something that would solve the problem presented in my original post. |
I don't think there is a solution to your problem. I think istream_range should have a member function to retrieve the cached element. And I think so the adaptors need a |
I would expect that snippet to print 6 consecutive strings from standard input. Instead, it prints 3, skips one, and then prints the next 3.
The text was updated successfully, but these errors were encountered: