This is a repost of a mail I sent to the libstdc++ mailing list, but it might
actually be interesting for libc++ as well. Here it is:
I have developed a small library to complete std::sort. Basically, the
idea is to use specific decicated algorithms for a small number of
values when that number of values is known at compile time. You can
find the library here: GitHub - Morwenn/cpp-sort: Sorting algorithms & related tools for C++14
When given an std::array, the sort function of the library uses a specific
sorting algorithm (based on sorting networks) for the given number of
values if it has one and falls back to std::sort if it doesn't. I
believe that it could be possible to add an overload to the
implementation of std::sort which would take instances of
std::array<T, N>::iterator and use a specific sorting algorithm
for small values of N. It would incur no runtime overhead and would
allow to sort small arrays for "free" instead of using the general
purpose version of std::sort which sometimes feel overkill for the job.
Would you be interested in such an optimization for libc++?