diff --git a/tstl/include/string_view.hpp b/tstl/include/string_view.hpp index 93cb8e5c..3e208c9f 100644 --- a/tstl/include/string_view.hpp +++ b/tstl/include/string_view.hpp @@ -180,6 +180,10 @@ static_assert(sizeof(string_view) == 16, "The size of a string_view must always // TODO Switch to C++14 and use constexpr for these functions +// Note: The identity_of_t trick is simply to ensure that template argument +// deduction is only done on one of the two arguments. This is allowing implicit +// conversion (string and string_view for instance) + // non-member comparison functions template @@ -187,31 +191,91 @@ bool operator==(basic_string_view x, basic_string_view y) noexcept return x.compare(y) == 0; } +template +bool operator==(basic_string_view x, std::identity_of_t> y) noexcept { + return x.compare(y) == 0; +} + +template +bool operator==(std::identity_of_t> x, basic_string_view y) noexcept { + return x.compare(y) == 0; +} + template bool operator!=(basic_string_view x, basic_string_view y) noexcept { return x.compare(y) != 0; } +template +bool operator!=(std::identity_of_t> x, basic_string_view y) noexcept { + return x.compare(y) != 0; +} + +template +bool operator!=(basic_string_view x, std::identity_of_t> y) noexcept { + return x.compare(y) != 0; +} + template bool operator<(basic_string_view x, basic_string_view y) noexcept { return x.compare(y) < 0; } +template +bool operator<(std::identity_of_t> x, basic_string_view y) noexcept { + return x.compare(y) < 0; +} + +template +bool operator<(basic_string_view x, std::identity_of_t> y) noexcept { + return x.compare(y) < 0; +} + template bool operator>(basic_string_view x, basic_string_view y) noexcept { return x.compare(y) > 0; } +template +bool operator>(std::identity_of_t> x, basic_string_view y) noexcept { + return x.compare(y) > 0; +} + +template +bool operator>(basic_string_view x, std::identity_of_t> y) noexcept { + return x.compare(y) > 0; +} + template bool operator<=(basic_string_view x, basic_string_view y) noexcept { return x.compare(y) <= 0; } +template +bool operator<=(std::identity_of_t> x, basic_string_view y) noexcept { + return x.compare(y) <= 0; +} + +template +bool operator<=(basic_string_view x, std::identity_of_t> y) noexcept { + return x.compare(y) <= 0; +} + template bool operator>=(basic_string_view x, basic_string_view y) noexcept { return x.compare(y) >= 0; } +template +bool operator>=(std::identity_of_t> x, basic_string_view y) noexcept { + return x.compare(y) >= 0; +} + +template +bool operator>=(basic_string_view x, std::identity_of_t> y) noexcept { + return x.compare(y) >= 0; +} + } //end of namespace std #endif