Morwenn / cpp-sort

Sorting algorithms & related tools for C++14
MIT License
621 stars 57 forks source link

Simple sorter options #207

Open Morwenn opened 2 years ago

Morwenn commented 2 years ago

Lots of sorters in the library have constexpr variables corresponding to various options:

All those options currently exist as details and are forced at compile time, but users have no control over them. I would like to expose several of these options so that users can change them freely. A simple way would be to create foobar_sorter_options objects, simple structs that can be passed to sorters at compile time thanks to NTTP.

Here is an example of what it could look like for drop_merge_sort:

constexpr cppsort::drop_merge_sorter_options options = {
    .recency = 8,
    .double_comparison = true
};
auto sort = cppsort::drop_merge_sorter<options>{};

Alternatively:

constexpr cppsort::drop_merge_sorter_options options = ;
auto sort = cppsort::drop_merge_sorter<{
    .recency = 8,
    .double_comparison = true
}>{};

The combination of NTTP and designated initializers would allow to pass all simple options in an option structure while naming them, which is IMO a superior solution to a sea of unnamable template parameters.


List of affected sorters and options.:


The list in the previous section is almost empty at the time of writing these words, and yet it already highlights some issues and design decisions to take into account: