Why can't the
std::vector<int> ints =
read_ints() | cont::sort | cont::unique;
from TFA can't be done "as lazily as possible" (i.e., sort eagerly and uniq lazily). Alternatively, something like std::vector<int> ints(read_ints() | cont::sort | cont::unique);
or even std::vector<int> ints;
read_ints() | cont::sort | cont::unique > ints;
What reason could we have for making `read_ints` and `unique` eager by default?Performance-wise, the lazy filter works in constant space, will result in fewer dcache misses if the data set is large, and (I think) provides more opportunity for the optimizer to do clever things. The eager chain may have better icache performance if the filter is very complicated.
And it's easy to go from lazy to eager -- just put everything in a vector. If you want to go from eager to lazy, though, you're out of luck.