Morwenn / cpp-sort

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

Handling the Ranges TS once merged into the standard #130

Open Morwenn opened 6 years ago

Morwenn commented 6 years ago

There are currently several papers in flight related to merging (parts of) the Ranges TS into the C++ IS. Those changes might come soon enough and will have a deep impact on several parts of cpp-sort, opening the way for a 2.0.0 breaking release. The following papers should be reviewed during the committee meetings to come:

cpp-sort 2.0.0 will have to take all those changes into account in order to modernize itself. The following changes will be needed to fully adapt:

Some of the issues described here are tracked in specific issues too, but an exhaustive list of the changes made by the Ranges TS is valuable enough. My main concern currently is that some of the things we do with our custom proxy iterator support are actually beyond the scopes of Ranges: I fear that associate_iterator will break.

Morwenn commented 3 years ago

Replacing cppsort::utility::identity with std::identity in branch 2.0.0-develop was fortunately as much of a no-brainer as I thought: a bit long but no big challenge occurred while doing it.

Instead of using std::identity when available in branch 1.x.y I'd rather make a CPPSORT_USE_STD_IDENTITY switch to conditionally make cppsort::utility::identity an alias of std::identity. There's not that much of a difference between both, but the current version supports operator| unlike std::identity, so it could still be a breaking change. As such I'd rather it be opt-in in branch 1.x.y instead of automatic .

Morwenn commented 3 years ago

Instead of introducing CPPSORT_USE_STD_IDENTITY and having more compile time switchs to test, more documentation to write about options, etc. I made what gives the most value added while being the least disruptive to branch 1.x.y: support for std::identity in places where it matters along the already existing support for utility::identity.

Morwenn commented 3 years ago

After having tried to replace std::less<> with std::ranges::less, a few tests broke because std::ranges::less requires the full zoo of comparison and relational operators for the type to compare through std::totally_ordered, which was immediately noticeable when the tests broke.

Instead I plan to add support for std::ranges::less and std::ranges::greater along the existing support for std::less<> and std::greater<>, conditionally in 1.x.y and unconditionally in 2.0.0-develop. It means a lot of overloads when using branch 1.x.y in C++20 mode, but the old comparison function objects are still more porweful (less restrictive) but users might want to use the next ones for the added security of constraints, so I can't not support them either.

The number of additional overloads to sorter_facade is a good argument for the clean break to C++20 in 2.0.0.

Morwenn commented 1 year ago

The groundwork for the concepts part is advancing slowly, mostly because the concepts used by cpp-sort are slightly different from those used by the standard library, especially in the following areas:

Support for a more powerful iter_move is kind of non-negotiable for the library, so I had to reimplement lots of standard library concepts (mostly stolen from libc++), and decided that I might as well tackle the other two bullet points. I started working on that, and the truth is that I don't just need to reimplement the standard library concepts, but also lots of the iterators and range utilities based on them. I do that on a as-needed basis, which ensures that all reimplemented components are implicitly tested by being used in the library - it notably avoids having to add lots of additional dedicated tests for stolen code.

The new iterator/sentinel model is more complicated than I expected it to be, so things aren't going quite fast and I need to change more parts of cpp-sort than expected, but I'm pretty confident that the end result makes it worth the cost.