Avoid std::set in script version checks

This commit is contained in:
Jonathan G Rennison
2023-08-19 16:36:32 +01:00
parent 1979fa9db1
commit 2bc943d31a
2 changed files with 8 additions and 6 deletions

View File

@@ -16,7 +16,8 @@
#include "../string_func.h"
#include "../rev.h"
#include "../core/format.hpp"
#include <set>
#include <algorithm>
#include <initializer_list>
#include "../safeguards.h"
@@ -26,8 +27,8 @@
*/
static bool CheckAPIVersion(const std::string &api_version)
{
static const std::set<std::string> versions = { "0.7", "1.0", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "1.10", "1.11", "12", "13", "14" };
return versions.find(api_version) != versions.end();
static constexpr std::initializer_list<const char*> versions{ "0.7", "1.0", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "1.10", "1.11", "12", "13", "14" };
return std::find_if(versions.begin(), versions.end(), [&](const char *v) { return api_version == v; }) != versions.end();
}
#if defined(_WIN32)

View File

@@ -13,7 +13,8 @@
#include "game_info.hpp"
#include "game_scanner.hpp"
#include "../debug.h"
#include <set>
#include <algorithm>
#include <initializer_list>
#include "../safeguards.h"
@@ -23,8 +24,8 @@
*/
static bool CheckAPIVersion(const std::string &api_version)
{
static const std::set<std::string> versions = { "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "1.10", "1.11", "12", "13", "14" };
return versions.find(api_version) != versions.end();
static constexpr std::initializer_list<const char*> versions{ "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "1.10", "1.11", "12", "13", "14" };
return std::find_if(versions.begin(), versions.end(), [&](const char *v) { return api_version == v; }) != versions.end();
}
#if defined(_WIN32)