.. _program_listing_file_include_partition.hpp: Program Listing for File partition.hpp ====================================== |exhale_lsh| :ref:`Return to documentation for file ` (``include/partition.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #pragma once #include "htlist.hpp" #include "predicates.hpp" #include namespace ctql { namespace detail { // partition_by_impl> // Produces two buckets: // - pass: elements where Rel::value is true // - fail: the remaining elements template class Rel, typename List> struct partition_by_impl; // Empty list -> both buckets empty. template class Rel> struct partition_by_impl> { using pass = HTList<>; using fail = HTList<>; }; // Step: peel head H; recurse on tail Ts... template class Rel, typename H, typename... Ts> struct partition_by_impl> { private: using rest = partition_by_impl>; public: using pass = std::conditional_t< Rel::value, typename append, typename rest::pass>::type, typename rest::pass>; using fail = std::conditional_t< Rel::value, typename rest::fail, typename append, typename rest::fail>::type>; }; } // namespace detail template class Rel, typename... Ts> struct partition_by { using impl = detail::partition_by_impl>; using pass = typename impl::pass; // kept / left bucket using fail = typename impl::fail; // rejected / right bucket using concat = typename detail::HTList; // pair as a two-element typelist }; template class Rel, typename... Ts> using filter_by = typename partition_by::pass; template class Rel, typename... Ts> using reject_if_by = typename partition_by::fail; template class Rel, template class KeyOf = Size, typename... Ts> using partition_by_key = partition_by...>; } // namespace ctql