3 ms·
I think it comes down to a "memory bug" vs. "performance bug" trade-off. If you make it default-lazy you run the risk of having the stream evaluated multiple ti
by zamalek 12y ago
I think it comes down to a "memory bug" vs. "performance bug" trade-off. If you make it default-lazy you run the risk of having the stream evaluated multiple times. If you make it default-eager you run the risk of O(N) memory (as you said).
I agree with your side of the trade-off, a performance bug (result: slow application) is always preferable to a memory bug (result: failed malloc, likely crash) in production.
To make things more desirable, you could always do something even simpler than your example:
auto ints = read_ints() | cont::sort | cont::unique | cont:to_vector;
That way fixing the performance bug would only need a one-liner.
Still, having the option is better than nothing.