3 ms·
Filters are used all the time in C++. * If the filtered result is used locally in a function (and then thrown away), a filtered view works just fine, is very
by gpderetta 10y ago
Filters are used all the time in C++.
* If the filtered result is used locally in a function (and then thrown away), a filtered view works just fine, is very cheap, efficient and is lazy (nice if you only consume a subset of it).
* Often only the filtered view is used, so you can destructively modify the original list, so no copies.
* If you need both the original list and the the filtered list, in a functional language you need to allocate new cons cells anyway. The cost of allocating, modifying and touching the new memory is going to dominate except for very long strings, so copying is not an issue.
Of course in C++ lists are frowned upon in the first place (as many algorithms can handle any data structure transparently), while they are kind of central in many functional languages.
There are cases of course where frictionless shared ownership is nice and GC shines. Filter is not one of them.
- rbehrends 10y ago> Filters are used all the time in C++. The problem is that you need a vastly more complex machinery to cover all the various ways to avoid copying/reference counting and then still don't have a general solution when you can't avoid multiple ownership (unless you count std::shared_ptr with its very high overhead). As I said before, it's not that you can't do it, it's that there are costs associated with it. > If you need both the original list and the the filtered list, in a functional language you need to allocate new cons cells anyway. You can filter arrays also and allocating cons cells for a list is pretty cheap with a modern GC, as discussed before.