zserio::StringView should be comparable with zserio::string
constexpr ::zserio::StringView stringView = ::zserio::makeStringView("any");
const ::zserio::string<> stringValue = "any";
constexpr std::string_view stdStringView = "any";
// ::zserio::StringView can be constructed directly from ::zserio::string
const bool compareWorkaround = (stringView == ::zserio::StringView(stringValue));
// but they can not be compared directly
//const bool compare1 = (stringView == stringValue);
//const bool compare2 = (stringValue == stringView);
// as a reference, string can be compared with std::string_view in c++17
const bool compareStd = (stdStringView == stringValue);
std approach works because std::string could convert itself to the std::string_view: https://en.cppreference.com/w/cpp/string/basic_string/operator_basic_string_view But this approach won't work for zserio::StringView.
The implicit zserio::StringView constructor doesn't work either: https://stackoverflow.com/questions/8890051/implicit-conversion-when-overloading-operators-for-template-classes
Maybe additional explicit compare operators could help. for instance (works but it's a rough suggestion):
template<typename CharT, class Traits>
constexpr bool operator==(BasicStringView<CharT, Traits> lhs, BasicStringView<CharT, Traits> rhs) noexcept
{
return lhs.compare(rhs) == 0;
}
template<typename CharT, class Traits, typename Other>
constexpr bool operator==(BasicStringView<CharT, Traits> lhs, const Other& rhs) noexcept
{
return lhs == ::zserio::BasicStringView<CharT, Traits>(rhs);
}
template<typename CharT, class Traits, typename Other>
constexpr bool operator==(const Other& lhs, BasicStringView<CharT, Traits> rhs) noexcept
{
return rhs == ::zserio::BasicStringView<CharT, Traits>(lhs);
}
Thanks a lot to pointing this out! The whole problem is caused by unacceptability of C++17 standard (too new). We stumbled upon this problem in past but we did not need this compare anywhere.
Global compare operator would probably solve this problem. We should investigate this more properly.