diff --git a/include/ctre/atoms_characters.hpp b/include/ctre/atoms_characters.hpp index fd9036fb..6ad5e588 100644 --- a/include/ctre/atoms_characters.hpp +++ b/include/ctre/atoms_characters.hpp @@ -24,13 +24,13 @@ template struct character { }; template struct negative_set { - template CTRE_FORCE_INLINE static constexpr bool match_char(CharT value) noexcept { + template CTRE_FORCE_INLINE static constexpr bool match_char([[maybe_unused]] CharT value) noexcept { return !(Content::match_char(value) || ... || false); } }; template struct set { - template CTRE_FORCE_INLINE static constexpr bool match_char(CharT value) noexcept { + template CTRE_FORCE_INLINE static constexpr bool match_char([[maybe_unused]] CharT value) noexcept { return (Content::match_char(value) || ... || false); } }; @@ -38,7 +38,7 @@ template struct set { template struct enumeration : set...> { }; template struct negate { - template CTRE_FORCE_INLINE static constexpr bool match_char(CharT value) noexcept { + template CTRE_FORCE_INLINE static constexpr bool match_char([[maybe_unused]] CharT value) noexcept { return !(Content::match_char(value) || ... || false); } }; diff --git a/include/ctre/evaluation.hpp b/include/ctre/evaluation.hpp index 6701c6fa..9238abad 100644 --- a/include/ctre/evaluation.hpp +++ b/include/ctre/evaluation.hpp @@ -136,11 +136,24 @@ constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, c // matching select in patterns template constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, const EndIterator end, const flags & f, R captures, ctll::list, Tail...>) noexcept { - if (auto r = evaluate(begin, current, end, f, captures, ctll::list())) { - return r; +#ifndef CTRE_DISABLE_GREEDY_OPT + if constexpr (sizeof...(TailOptions) > 0 && !collides(calculate_first(sequence{}), calculate_first(sequence, Tail...>{}))) { + auto r = evaluate(begin, current, end, f, captures, ctll::list{}))), end_cycle_mark>{}); + if (r) { + return evaluate(begin, current, end, f, captures, ctll::list{}); + } else { + return evaluate(begin, current, end, f, captures, ctll::list, Tail...>()); + } } else { - return evaluate(begin, current, end, f, captures, ctll::list, Tail...>()); +#endif + if (auto r = evaluate(begin, current, end, f, captures, ctll::list())) { + return r; + } else { + return evaluate(begin, current, end, f, captures, ctll::list, Tail...>()); + } +#ifndef CTRE_DISABLE_GREEDY_OPT } +#endif } template diff --git a/include/ctre/first.hpp b/include/ctre/first.hpp index 65ef7ac0..ac8edd72 100644 --- a/include/ctre/first.hpp +++ b/include/ctre/first.hpp @@ -368,6 +368,21 @@ template constexpr void negative_helper(ctre::negative_set<>, CB & } } +template +constexpr auto transform_into_set(ctll::list) { + return ctre::set{}; +} + +template +constexpr auto transform_into_set(T) { + return T{}; +} + +template<> +constexpr auto transform_into_set(can_be_anything) { + return ctre::char_range::min(), std::numeric_limits::max()>{}; +} + // simple fixed set // TODO: this needs some optimizations template class point_set { @@ -469,6 +484,9 @@ template class point_set { constexpr bool check(can_be_anything) { return used > 0; } + constexpr bool check(empty) { + return used == 0; + } template constexpr bool check(ctre::negative_set nset) { bool collision = false; negative_helper(nset, [&](int64_t low, int64_t high){ @@ -497,6 +515,9 @@ template class point_set { constexpr void populate(can_be_anything) { insert(std::numeric_limits::min(), std::numeric_limits::max()); } + constexpr void populate(empty) { + //do nothing + } template constexpr void populate(ctre::negative_set nset) { negative_helper(nset, [&](int64_t low, int64_t high){ this->insert(low, high);