Refactor Support.

This commit is contained in:
ykiko
2024-12-04 01:12:40 +08:00
parent ac7ce3aa6a
commit 2baea3800a
26 changed files with 1173 additions and 600 deletions

42
include/Support/Compare.h Normal file
View File

@@ -0,0 +1,42 @@
#pragma once
#include "Struct.h"
namespace clice::support {
constexpr auto equal(const auto& lhs, const auto& rhs) {
if constexpr(requires { lhs == rhs; }) {
return (lhs == rhs);
} else {
return support::foreach(lhs, rhs, [](const auto& lhs, const auto& rhs) {
return support::equal(lhs, rhs);
});
}
}
/// Compare lhs and rhs according to the dictionary order of their members.
constexpr auto less(const auto& lhs, const auto& rhs) {
if constexpr(requires { lhs < rhs; }) {
return (lhs < rhs);
} else {
bool result = false;
support::foreach(lhs, rhs, [&result](const auto& lhs, const auto& rhs) {
/// if lhs less than rhs, abort the iteration and return true.
if(support::less(lhs, rhs)) {
result = true;
return false;
}
/// if lhs equal to rhs, continue to next member.
if(support::equal(lhs, rhs)) {
return true;
}
/// if lhs greater than rhs, abort the iteration and return false.
return false;
});
return result;
}
}
} // namespace clice::support