-
Notifications
You must be signed in to change notification settings - Fork 58
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
Mutable sorters #104
Comments
Another problem actually shows up: proper EDIT: managed to make it with a workaround without duplicating the code. I'm in the process of trying to make the adapters work smoothly with either |
Update: while the main design questions are solved, the branch is currently blocked by what appear to be ICE in Clang, no matter what I try. Help wanted to fix the Clang build .___. |
While mutable sorters are still blocked by the aforementioned issues (ICE and unacceptable compile times), it might be possible to split the features and implement stateful sorters, albeit not allowing them to be modified by the sorting operation. It may solve the compile time issues since we don't have to introduce a double-indirection at every level to handle the |
I had to wait for the C++23 feature Deducing |
cpp-sort currently gives the middle finger to mutable sorters, which might not be the right reaction to have. It never really mattered because every sorter in the library is immutable. However, we might want to have mutable sorters at some point, for example sorters that can reuse memory instead of allocating new memory whenever they're called. A few design points to take into account:
sorter_facade
wil have to handle thatstd::is_empty
check should be enough to guarantee immutabilityutility::is_immutable
trait which falls back tostd::is_empty
and can be specialized by usersMutable sorters could allow to pass additional runtime parameters to existing sorter. For example
counting_sorter
needs one less pass over the collection if themin
andmax
values are known ahead of the sort. They could be passed as follows:counting_sorter(min, max)(collection);
Such a sorter wouldn't be convertible to a function pointer, but it allows to pass additional runtime parameters to the sorter without having to change the generic sorting interface. Basically: constructor parameters would serve to pass sorter-specific parameters while function-call parameters would serve to pass the generic collection/comparison/projection parameters. Hence mutable sorters are useful.
Another example: one could pass a runtime buffer to merge-sort so that several calls to the algorithm are able to reuse the same memory instead of allocating its own.
Usual TODO list:
sorter_facade
handle mutable sortershybrid_adapter
properlyThe text was updated successfully, but these errors were encountered: