summaryrefslogtreecommitdiff
path: root/Source/cmFindPackageCommand.cxx
diff options
context:
space:
mode:
authorAlex Turbov <i.zaufi@gmail.com>2022-06-27 08:17:46 +0400
committerAlex Turbov <i.zaufi@gmail.com>2022-07-11 17:14:01 +0400
commit6a95ab97e77faca8ba7775683f307cd32c82f47f (patch)
treee881231e3d5bbc5e206210c47588594109f61344 /Source/cmFindPackageCommand.cxx
parentc6d3ef1c95ed3b3a13ee3a3b2cb00112f1a2bda8 (diff)
downloadcmake-6a95ab97e77faca8ba7775683f307cd32c82f47f.tar.gz
cmFindPackageCommand: Deduplicate version string comparator code
Diffstat (limited to 'Source/cmFindPackageCommand.cxx')
-rw-r--r--Source/cmFindPackageCommand.cxx33
1 files changed, 15 insertions, 18 deletions
diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx
index 0347d58fe1..75aaba14bf 100644
--- a/Source/cmFindPackageCommand.cxx
+++ b/Source/cmFindPackageCommand.cxx
@@ -45,6 +45,19 @@
class cmExecutionStatus;
class cmFileList;
+namespace {
+
+template <template <typename> class Op>
+struct StrverscmpOp
+{
+ bool operator()(const std::string& lhs, const std::string& rhs) const
+ {
+ return Op<int>()(cmSystemTools::strverscmp(lhs, rhs), 0);
+ }
+};
+
+} // anonymous namespace
+
cmFindPackageCommand::PathLabel
cmFindPackageCommand::PathLabel::PackageRedirect("PACKAGE_REDIRECT");
cmFindPackageCommand::PathLabel cmFindPackageCommand::PathLabel::UserRegistry(
@@ -59,22 +72,6 @@ const cm::string_view cmFindPackageCommand::VERSION_ENDPOINT_INCLUDED(
const cm::string_view cmFindPackageCommand::VERSION_ENDPOINT_EXCLUDED(
"EXCLUDE");
-struct StrverscmpGreater
-{
- bool operator()(const std::string& lhs, const std::string& rhs) const
- {
- return cmSystemTools::strverscmp(lhs, rhs) > 0;
- }
-};
-
-struct StrverscmpLesser
-{
- bool operator()(const std::string& lhs, const std::string& rhs) const
- {
- return cmSystemTools::strverscmp(lhs, rhs) < 0;
- }
-};
-
void cmFindPackageCommand::Sort(std::vector<std::string>::iterator begin,
std::vector<std::string>::iterator end,
SortOrderType order, SortDirectionType dir)
@@ -90,9 +87,9 @@ void cmFindPackageCommand::Sort(std::vector<std::string>::iterator begin,
// compared such that e.g. 000 00 < 01 < 010 < 09 < 0 < 1 < 9 < 10
{
if (dir == Dec) {
- std::sort(begin, end, StrverscmpGreater());
+ std::sort(begin, end, StrverscmpOp<std::greater>());
} else {
- std::sort(begin, end, StrverscmpLesser());
+ std::sort(begin, end, StrverscmpOp<std::less>());
}
}
// else do not sort