Modernize std::transform with ranges

In StringUtil.h, the lambdas wrapping `Common::ToLower(char)` and `Common::ToUpper(char)` were only necessary due to the function names being overloaded.
This commit is contained in:
mitaclaw 2024-09-29 10:44:00 -07:00
parent 7ce170f138
commit 72436a0d1f
4 changed files with 6 additions and 7 deletions

View File

@ -655,12 +655,12 @@ std::string GetEscapedHtml(std::string html)
void ToLower(std::string* str)
{
std::transform(str->begin(), str->end(), str->begin(), [](char c) { return Common::ToLower(c); });
std::ranges::transform(*str, str->begin(), static_cast<char (&)(char)>(Common::ToLower));
}
void ToUpper(std::string* str)
{
std::transform(str->begin(), str->end(), str->begin(), [](char c) { return Common::ToUpper(c); });
std::ranges::transform(*str, str->begin(), static_cast<char (&)(char)>(Common::ToUpper));
}
bool CaseInsensitiveEquals(std::string_view a, std::string_view b)

View File

@ -70,7 +70,7 @@ CameraLogic::GetCameraPoints(const Common::Matrix44& transform, Common::Vec2 fie
std::array<CameraPoint, CameraLogic::NUM_POINTS> camera_points;
std::transform(leds.begin(), leds.end(), camera_points.begin(), [&](const Vec3& v) {
std::ranges::transform(leds, camera_points.begin(), [&](const Vec3& v) {
const auto point = camera_view * Vec4(v, 1.0);
// Check if LED is behind camera.

View File

@ -130,8 +130,7 @@ void InterfacePane::CreateUI()
Common::DoFileSearch({File::GetUserPath(D_THEMES_IDX), File::GetSysDirectory() + THEMES_DIR});
std::vector<std::string> theme_names;
theme_names.reserve(theme_paths.size());
std::transform(theme_paths.cbegin(), theme_paths.cend(), std::back_inserter(theme_names),
PathToFileName);
std::ranges::transform(theme_paths, std::back_inserter(theme_names), PathToFileName);
// Theme Combobox
m_combobox_theme = new ConfigStringChoice(theme_names, Config::MAIN_THEME_NAME);

View File

@ -143,8 +143,8 @@ void ToolBar::MakeActions()
}
std::vector<int> widths;
std::transform(items.begin(), items.end(), std::back_inserter(widths),
[](QWidget* item) { return item->sizeHint().width(); });
std::ranges::transform(items, std::back_inserter(widths),
[](QWidget* item) { return item->sizeHint().width(); });
const int min_width = *std::max_element(widths.begin(), widths.end()) * 0.85;
for (QWidget* widget : items)