summaryrefslogtreecommitdiffstats
path: root/Source/cmStandardLevelResolver.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-10-04 17:38:01 (GMT)
committerBrad King <brad.king@kitware.com>2023-10-04 21:14:58 (GMT)
commit99fa01d3faa70f1e214acd56ce25002ae310c51d (patch)
tree1ac54a53b77808ab8a56a4fd5b36e041d110add1 /Source/cmStandardLevelResolver.cxx
parentfdd81a609a5f581d0bf6f935d3580377361a4b31 (diff)
downloadCMake-99fa01d3faa70f1e214acd56ce25002ae310c51d.zip
CMake-99fa01d3faa70f1e214acd56ce25002ae310c51d.tar.gz
CMake-99fa01d3faa70f1e214acd56ce25002ae310c51d.tar.bz2
cmStandardLevelResolver: Factor out public representation of level
Diffstat (limited to 'Source/cmStandardLevelResolver.cxx')
-rw-r--r--Source/cmStandardLevelResolver.cxx32
1 files changed, 15 insertions, 17 deletions
diff --git a/Source/cmStandardLevelResolver.cxx b/Source/cmStandardLevelResolver.cxx
index 469bef8..41dd316 100644
--- a/Source/cmStandardLevelResolver.cxx
+++ b/Source/cmStandardLevelResolver.cxx
@@ -13,6 +13,7 @@
#include <vector>
#include <cm/iterator>
+#include <cm/optional>
#include <cm/string_view>
#include <cmext/algorithm>
#include <cmext/string_view>
@@ -25,6 +26,7 @@
#include "cmMakefile.h"
#include "cmMessageType.h"
#include "cmPolicies.h"
+#include "cmStandardLevel.h"
#include "cmStringAlgorithms.h"
#include "cmTarget.h"
#include "cmValue.h"
@@ -46,12 +48,6 @@ const char* const HIP_FEATURES[] = { nullptr FOR_EACH_HIP_FEATURE(
FEATURE_STRING) };
#undef FEATURE_STRING
-struct StandardNeeded
-{
- int index;
- int value;
-};
-
int ParseStd(std::string const& level)
{
try {
@@ -352,7 +348,8 @@ struct StandardLevelComputer
newRequiredStandard.clear();
}
- auto needed = this->HighestStandardNeeded(makefile, feature);
+ cm::optional<cmStandardLevel> needed =
+ this->HighestStandardNeeded(makefile, feature);
cmValue existingStandard = currentLangStandardValue;
if (!existingStandard) {
@@ -382,12 +379,12 @@ struct StandardLevelComputer
}
}
- if (needed.index != -1) {
+ if (needed) {
// Ensure the C++ language level is high enough to support
// the needed C++ features.
if (existingLevelIter == cm::cend(this->Levels) ||
- existingLevelIter < this->Levels.begin() + needed.index) {
- newRequiredStandard = this->LevelsAsStrings[needed.index];
+ existingLevelIter < this->Levels.begin() + needed->Index()) {
+ newRequiredStandard = this->LevelsAsStrings[needed->Index()];
}
}
@@ -439,23 +436,24 @@ struct StandardLevelComputer
return false;
}
- auto needed = this->HighestStandardNeeded(makefile, feature);
+ cm::optional<cmStandardLevel> needed =
+ this->HighestStandardNeeded(makefile, feature);
- return (needed.index == -1) ||
- (this->Levels.begin() + needed.index) <= existingLevelIter;
+ return !needed ||
+ (this->Levels.begin() + needed->Index()) <= existingLevelIter;
}
- StandardNeeded HighestStandardNeeded(cmMakefile* makefile,
- std::string const& feature) const
+ cm::optional<cmStandardLevel> HighestStandardNeeded(
+ cmMakefile* makefile, std::string const& feature) const
{
std::string prefix = cmStrCat("CMAKE_", this->Language);
- StandardNeeded maxLevel = { -1, -1 };
+ cm::optional<cmStandardLevel> maxLevel;
for (size_t i = 0; i < this->Levels.size(); ++i) {
if (cmValue prop = makefile->GetDefinition(
cmStrCat(prefix, this->LevelsAsStrings[i], "_COMPILE_FEATURES"))) {
cmList props{ *prop };
if (cm::contains(props, feature)) {
- maxLevel = { static_cast<int>(i), this->Levels[i] };
+ maxLevel = cmStandardLevel(i);
}
}
}