本文整理汇总了C++中path::compare方法的典型用法代码示例。如果您正苦于以下问题:C++ path::compare方法的具体用法?C++ path::compare怎么用?C++ path::compare使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类path
的用法示例。
在下文中一共展示了path::compare方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_compare_basic
void test_compare_basic()
{
using namespace fs;
for (auto const & TC : CompareTestCases) {
const path p1(TC.LHS);
const path p2(TC.RHS);
const std::string R(TC.RHS);
const std::string_view RV(TC.RHS);
const int E = TC.expect;
{ // compare(...) functions
DisableAllocationGuard g; // none of these operations should allocate
// check runtime results
int ret1 = normalize_ret(p1.compare(p2));
int ret2 = normalize_ret(p1.compare(R));
int ret3 = normalize_ret(p1.compare(TC.RHS));
int ret4 = normalize_ret(p1.compare(RV));
g.release();
ASSERT_EQ(ret1, ret2);
ASSERT_EQ(ret1, ret3);
ASSERT_EQ(ret1, ret4);
ASSERT_EQ(ret1, E)
<< DISPLAY(TC.LHS) << DISPLAY(TC.RHS);
// check signatures
ASSERT_NOEXCEPT(p1.compare(p2));
}
{ // comparison operators
DisableAllocationGuard g; // none of these operations should allocate
// Check runtime result
assert((p1 == p2) == (E == 0));
assert((p1 != p2) == (E != 0));
assert((p1 < p2) == (E < 0));
assert((p1 <= p2) == (E <= 0));
assert((p1 > p2) == (E > 0));
assert((p1 >= p2) == (E >= 0));
// Check signatures
ASSERT_NOEXCEPT(p1 == p2);
ASSERT_NOEXCEPT(p1 != p2);
ASSERT_NOEXCEPT(p1 < p2);
ASSERT_NOEXCEPT(p1 <= p2);
ASSERT_NOEXCEPT(p1 > p2);
ASSERT_NOEXCEPT(p1 >= p2);
}
{ // check hash values
auto h1 = hash_value(p1);
auto h2 = hash_value(p2);
assert((h1 == h2) == (p1 == p2));
// check signature
ASSERT_SAME_TYPE(size_t, decltype(hash_value(p1)));
ASSERT_NOEXCEPT(hash_value(p1));
}
}
}
示例2: main
int main()
{
using namespace fs;
for (auto const & TC : CompareTestCases) {
const path p1(TC.LHS);
const path p2(TC.RHS);
const std::string R(TC.RHS);
const std::string_view RV(TC.RHS);
const int E = TC.expect;
{ // compare(...) functions
DisableAllocationGuard g; // none of these operations should allocate
// check runtime results
int ret1 = p1.compare(p2);
int ret2 = p1.compare(R);
int ret3 = p1.compare(TC.RHS);
int ret4 = p1.compare(RV);
assert(ret1 == ret2 && ret1 == ret3 && ret1 == ret4);
int normalized_ret = ret1 < 0 ? -1 : (ret1 > 0 ? 1 : 0);
assert(normalized_ret == E);
// check signatures
ASSERT_NOEXCEPT(p1.compare(p2));
}
{ // comparison operators
DisableAllocationGuard g; // none of these operations should allocate
// Check runtime result
assert((p1 == p2) == (E == 0));
assert((p1 != p2) == (E != 0));
assert((p1 < p2) == (E < 0));
assert((p1 <= p2) == (E <= 0));
assert((p1 > p2) == (E > 0));
assert((p1 >= p2) == (E >= 0));
// Check signatures
ASSERT_NOEXCEPT(p1 == p2);
ASSERT_NOEXCEPT(p1 != p2);
ASSERT_NOEXCEPT(p1 < p2);
ASSERT_NOEXCEPT(p1 <= p2);
ASSERT_NOEXCEPT(p1 > p2);
ASSERT_NOEXCEPT(p1 >= p2);
}
{ // check hash values
auto h1 = hash_value(p1);
auto h2 = hash_value(p2);
assert((h1 == h2) == (p1 == p2));
// check signature
ASSERT_SAME_TYPE(size_t, decltype(hash_value(p1)));
ASSERT_NOEXCEPT(hash_value(p1));
}
}
}
示例3:
bool operator<(const path& lhs, const path& rhs) noexcept
{
return lhs.compare(rhs) < 0;
}