Skip to content

Commit

Permalink
refactor: Implement workaround for MSVC 17.10 (cl 19.40)
Browse files Browse the repository at this point in the history
  • Loading branch information
slavek-kucera authored May 31, 2024
1 parent 2d8b98d commit b9c590a
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions utils/include/utils/text_matchers.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <array>
#include <cctype>
#include <concepts>
#include <optional>
#include <string_view>
#include <type_traits>
Expand Down Expand Up @@ -210,16 +211,28 @@ class space_matcher
}
};

template<typename DefaultStringMatcher>
struct matcher_convertor
{
template<typename T>
constexpr T&& operator()(T&& t) const noexcept
{
return std::forward<T>(t);
}
template<std::convertible_to<std::string_view> T>
constexpr DefaultStringMatcher operator()(T&& t) const noexcept(std::is_nothrow_convertible_v<T, std::string_view>)
{
return DefaultStringMatcher(std::forward<T>(t));
}
};
template<typename DefaultStringMatcher>
constexpr const matcher_convertor<DefaultStringMatcher> convert_matcher;

template<typename DefaultStringMatcher = void, typename... Matchers>
constexpr auto seq(Matchers&&... matchers)
{
constexpr auto convert = []<typename T>(T&& t) {
if constexpr (std::is_convertible_v<T&&, std::string_view>)
return DefaultStringMatcher(std::forward<T>(t));
else
return std::forward<T>(t);
};
return [... matchers = convert(std::forward<Matchers>(matchers))]<typename It>(It& b, const It& e) noexcept {
return [... matchers = convert_matcher<DefaultStringMatcher>(std::forward<Matchers>(matchers))]<typename It>(
It& b, const It& e) noexcept {
auto work = b;
return ((matchers(work, e) && ...)) && (b = work, true);
};
Expand All @@ -228,13 +241,7 @@ constexpr auto seq(Matchers&&... matchers)
template<typename DefaultStringMatcher = void, typename... Matchers>
constexpr auto alt(Matchers&&... matchers)
{
constexpr auto convert = []<typename T>(T&& t) {
if constexpr (std::is_convertible_v<T&&, std::string_view>)
return DefaultStringMatcher(std::forward<T>(t));
else
return std::forward<T>(t);
};
return [... matchers = convert(std::forward<Matchers>(matchers))]<typename It>(
return [... matchers = convert_matcher<DefaultStringMatcher>(std::forward<Matchers>(matchers))]<typename It>(
It& b, const It& e) noexcept { return ((matchers(b, e) || ...)); };
}

Expand Down

0 comments on commit b9c590a

Please sign in to comment.