From 72436a0d1f0c9c4c67f8763e0ec2f0941a975e02 Mon Sep 17 00:00:00 2001 From: mitaclaw <140017135+mitaclaw@users.noreply.github.com> Date: Sun, 29 Sep 2024 10:44:00 -0700 Subject: [PATCH] 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. --- Source/Core/Common/StringUtil.cpp | 4 ++-- Source/Core/Core/HW/WiimoteEmu/Camera.cpp | 2 +- Source/Core/DolphinQt/Settings/InterfacePane.cpp | 3 +-- Source/Core/DolphinQt/ToolBar.cpp | 4 ++-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Source/Core/Common/StringUtil.cpp b/Source/Core/Common/StringUtil.cpp index 9881708a27..d3e7caacdf 100644 --- a/Source/Core/Common/StringUtil.cpp +++ b/Source/Core/Common/StringUtil.cpp @@ -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(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(Common::ToUpper)); } bool CaseInsensitiveEquals(std::string_view a, std::string_view b) diff --git a/Source/Core/Core/HW/WiimoteEmu/Camera.cpp b/Source/Core/Core/HW/WiimoteEmu/Camera.cpp index 7b68ab9d5f..1dcdb77952 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Camera.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/Camera.cpp @@ -70,7 +70,7 @@ CameraLogic::GetCameraPoints(const Common::Matrix44& transform, Common::Vec2 fie std::array 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. diff --git a/Source/Core/DolphinQt/Settings/InterfacePane.cpp b/Source/Core/DolphinQt/Settings/InterfacePane.cpp index 1fc0caea71..e52fb69200 100644 --- a/Source/Core/DolphinQt/Settings/InterfacePane.cpp +++ b/Source/Core/DolphinQt/Settings/InterfacePane.cpp @@ -130,8 +130,7 @@ void InterfacePane::CreateUI() Common::DoFileSearch({File::GetUserPath(D_THEMES_IDX), File::GetSysDirectory() + THEMES_DIR}); std::vector 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); diff --git a/Source/Core/DolphinQt/ToolBar.cpp b/Source/Core/DolphinQt/ToolBar.cpp index 74a31dcfde..9649af6b00 100644 --- a/Source/Core/DolphinQt/ToolBar.cpp +++ b/Source/Core/DolphinQt/ToolBar.cpp @@ -143,8 +143,8 @@ void ToolBar::MakeActions() } std::vector 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)