.. _program_listing_file_include_sorted.hpp: Program Listing for File sorted.hpp =================================== |exhale_lsh| :ref:`Return to documentation for file ` (``include/sorted.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #pragma once #include "partition.hpp" #include "predicates.hpp" #include "htlist.hpp" namespace ctql { enum class Order { Asc, Desc }; template struct sort_list; template struct sort_list> { using type = detail::HTList<>; }; template struct sort_list> { private: // Choose relational operators based on order: // Asc: Left = "<", Right = ">=" // Desc: Left = ">", Right = "<=" using LeftRel = std::conditional_t, op_type<">"_ct>>; using RightRel = std::conditional_t="_ct>, op_type<"<="_ct>>; // Partition the tail TRest... with respect to pivot T0. // P::pass => elements on the Left side (strict compare vs pivot) // Not-pass => elements on the Right side (>= or <= vs pivot) using P = partition_by; using LeftSorted = typename sort_list::type; using RightUnsorted = filter_by; using RightSorted = typename sort_list::type; public: // Concatenate: LeftSorted ++ [T0] ++ RightSorted using type = typename detail::append< typename detail::append>::type, RightSorted >::type; }; template class KeyOf = Size, typename... Ts> using TypeSort = typename sort_list...>>::type; } // namespace ctql