.. _program_listing_file_include_match.hpp: Program Listing for File match.hpp ================================== |exhale_lsh| :ref:`Return to documentation for file ` (``include/match.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #pragma once // ctql/match.hpp #include namespace ctql { template struct case_ { static constexpr auto key = K; using type = T; }; template struct default_ { using type = T; }; namespace detail { // -------- matcher core (first-match wins; default if no match) -------- template struct match_impl; // End of list -> yield accumulated Default. template struct match_impl { using type = Default; }; // case_ step: if not matched yet and Key == K, lock in T; otherwise keep going. template struct match_impl, Rest...> : match_impl< Key, std::conditional_t, (Matched || (Key == K)), Rest...> { }; // default_ step: if not matched yet, update fallback; otherwise ignore. template struct match_impl, Rest...> : match_impl, Matched, Rest...> { }; // Public interface wrapper. template struct match { using type = typename match_impl::type; }; } // namespace detail template using match_t = typename detail::match::type; } // namespace ctql