5 ms·
In my experience, it's really important to be able to look at some code and know its performance characteristics: does it allocate memory? Who is managing the l
by eric_niebler 12y ago
In my experience, it's really important to be able to look at some code and know its performance characteristics: does it allocate memory? Who is managing the lifetime of the objects and how many times are the elements copied/moved? How many passes over the data are made? The separation of eager from lazy adaptors makes it possible to know those performance characteristics at a glance.
Looking at your code:
std::vector<int> ints;
read_ints() | cont::sort | cont::unique > ints;
If `cont::unique` is lazy (non-owning), what is the lifetime of the elements allocated by `cont::sort` (or moved from `read_ints()`)? If the code had been written instead like below, who is responsible for keeping the elements alive?
std::vector<int> ints;
auto tmp = read_ints() | cont::sort | cont::unique;
tmp > ints;
There's a whole host of issues here that you're not dealing with.