mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-30 17:06:40 +00:00
Support asymmetric comparison between ESM::RefId and std::string_view
This commit is contained in:
parent
6f329f3d40
commit
cd6a5b5a0e
3 changed files with 32 additions and 3 deletions
|
@ -3,6 +3,7 @@
|
|||
#include <gtest/gtest.h>
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace ESM
|
||||
|
@ -122,5 +123,26 @@ namespace ESM
|
|||
const std::string_view b = "B";
|
||||
EXPECT_LT(a, b);
|
||||
}
|
||||
|
||||
TEST(ESMRefIdTest, hasCaseInsensitiveStrongOrderWithStringView)
|
||||
{
|
||||
const RefId a = RefId::stringRefId("a");
|
||||
const std::string_view b = "B";
|
||||
const RefId c = RefId::stringRefId("c");
|
||||
EXPECT_LT(a, b);
|
||||
EXPECT_LT(b, c);
|
||||
}
|
||||
|
||||
TEST(ESMRefIdTest, canBeUsedAsMapKeyWithLookupByStringView)
|
||||
{
|
||||
const std::map<ESM::RefId, int, std::less<>> map({ { ESM::RefId::stringRefId("a"), 42 } });
|
||||
EXPECT_EQ(map.count("A"), 1);
|
||||
}
|
||||
|
||||
TEST(ESMRefIdTest, canBeUsedAsLookupKeyForMapWithStringKey)
|
||||
{
|
||||
const std::map<std::string, int, std::less<>> map({ { "a", 42 } });
|
||||
EXPECT_EQ(map.count(ESM::RefId::stringRefId("A")), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,9 +16,14 @@ namespace ESM
|
|||
return Misc::StringUtils::ciLess(mId, rhs.mId);
|
||||
}
|
||||
|
||||
bool RefId::operator<(std::string_view rhs) const
|
||||
bool operator<(const RefId& lhs, std::string_view rhs)
|
||||
{
|
||||
return Misc::StringUtils::ciLess(mId, rhs);
|
||||
return Misc::StringUtils::ciLess(lhs.mId, rhs);
|
||||
}
|
||||
|
||||
bool operator<(std::string_view lhs, const RefId& rhs)
|
||||
{
|
||||
return Misc::StringUtils::ciLess(lhs, rhs.mId);
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const RefId& refId)
|
||||
|
|
|
@ -39,7 +39,9 @@ namespace ESM
|
|||
|
||||
bool operator<(const RefId& rhs) const;
|
||||
|
||||
bool operator<(std::string_view rhs) const;
|
||||
friend bool operator<(const RefId& lhs, std::string_view rhs);
|
||||
|
||||
friend bool operator<(std::string_view lhs, const RefId& rhs);
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& os, const RefId& dt);
|
||||
|
||||
|
|
Loading…
Reference in a new issue