Skip to content

Commit d7cec4e

Browse files
committed
avoid default lambda captures
1 parent 5003ae4 commit d7cec4e

22 files changed

Lines changed: 203 additions & 170 deletions

src/display/Connections.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ void ConnectionDrawer::ConnectionFakeGL::drawLineStrip(const std::vector<glm::ve
799799
const float extension = CONNECTION_LINE_WIDTH * 0.5f;
800800

801801
// Helper lambda to generate a quad between two points with a specific color.
802-
auto generateQuad = [&](const glm::vec3 &p1, const glm::vec3 &p2, const Color quad_color) {
802+
auto generateQuad = [this](const glm::vec3 &p1, const glm::vec3 &p2, const Color quad_color) {
803803
auto &verts = deref(m_currentBuffer).quadVerts;
804804

805805
const glm::vec3 segment = p2 - p1;

src/display/Infomarks.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ BatchedInfomarksMeshes MapCanvas::getInfomarksMeshes()
9999
{
100100
const auto &map = m_data.getCurrentMap();
101101
const auto &db = map.getInfomarkDb();
102-
db.getIdSet().for_each([&](const InfomarkId id) {
102+
db.getIdSet().for_each([&db, &result](const InfomarkId id) {
103103
InfomarkHandle mark{db, id};
104104
const int layer = mark.getPosition1().z;
105105
const auto it = result.find(layer);
@@ -125,8 +125,9 @@ BatchedInfomarksMeshes MapCanvas::getInfomarksMeshes()
125125
for (auto &it : result) {
126126
const int layer = it.first;
127127
InfomarksBatch batch{getOpenGL(), getGLFont()};
128-
db.getIdSet().for_each(
129-
[&](const InfomarkId id) { drawInfomark(batch, InfomarkHandle{db, id}, layer); });
128+
db.getIdSet().for_each([this, &batch, &db, layer](const InfomarkId id) {
129+
drawInfomark(batch, InfomarkHandle{db, id}, layer);
130+
});
130131
it.second = batch.getMeshes();
131132
}
132133

@@ -370,7 +371,7 @@ void MapCanvas::paintSelectedInfomarks()
370371

371372
const auto &map = m_data.getCurrentMap();
372373
const InfomarkDb &db = map.getInfomarkDb();
373-
db.getIdSet().for_each([&](const InfomarkId id) {
374+
db.getIdSet().for_each([&db, &drawSelectionPoints](const InfomarkId id) {
374375
InfomarkHandle marker{db, id};
375376
drawSelectionPoints(marker);
376377
});

src/display/Textures.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,8 @@ void MapCanvas::initTextures()
610610
}
611611
};
612612

613-
auto initGroup = [&](const std::string_view groupName, auto &&...sources) {
613+
auto initGroup = [&maybeCreateArray2](const std::string_view groupName,
614+
auto &&...sources) -> SharedMMTexture {
614615
SharedMMTexture pArrayTex;
615616
auto thing = combine(std::forward<decltype(sources)>(sources)...);
616617
maybeCreateArray2(groupName, thing, pArrayTex);
@@ -633,12 +634,14 @@ void MapCanvas::initTextures()
633634
textures.exit_down,
634635
textures.exit_up);
635636

636-
auto maybeCreateArray =
637-
[&](const std::string_view groupName, auto &thing, SharedMMTexture &pArrayTex) {
638-
if (pArrayTex)
639-
return;
640-
pArrayTex = initGroup(groupName, thing);
641-
};
637+
auto maybeCreateArray = [&initGroup](const std::string_view groupName,
638+
auto &thing,
639+
SharedMMTexture &pArrayTex) {
640+
if (pArrayTex) {
641+
return;
642+
}
643+
pArrayTex = initGroup(groupName, thing);
644+
};
642645

643646
#define XTEX(_TYPE, _NAME) maybeCreateArray(#_NAME, textures._NAME, textures._NAME##_Array);
644647
XFOREACH_MAPCANVAS_TEXTURES(XTEX)

src/display/mapcanvas_gl.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ void MapCanvas::Diff::maybeAsyncUpdate(const Map &saved, const Map &current)
620620

621621
// Handle rooms needing a server ID or that are temporary
622622
if (showNeedsServerId) {
623-
current.getRooms().for_each([&](auto id) {
623+
current.getRooms().for_each([&current, &drawQuad](auto id) {
624624
if (auto h = current.getRoomHandle(id)) {
625625
if (h.isTemporary()) {
626626
drawQuad(h.getRaw(), NamedColorEnum::HIGHLIGHT_TEMPORARY);
@@ -634,9 +634,12 @@ void MapCanvas::Diff::maybeAsyncUpdate(const Map &saved, const Map &current)
634634
// Handle changed rooms
635635
if (showChanged) {
636636
ProgressCounter dummyPc;
637-
Map::foreachChangedRoom(dummyPc, saved, current, [&](const RawRoom &room) {
638-
drawQuad(room, NamedColorEnum::HIGHLIGHT_UNSAVED);
639-
});
637+
Map::foreachChangedRoom(dummyPc,
638+
saved,
639+
current,
640+
[&drawQuad](const RawRoom &room) {
641+
drawQuad(room, NamedColorEnum::HIGHLIGHT_UNSAVED);
642+
});
640643
}
641644

642645
if (highlights.empty()) {

src/global/emojis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ static void importEmojis(const QByteArray &bytes, const QString &filename)
643643
auto &emojis = getEmojis();
644644
emojis.reset();
645645
size_t num_output_emojis = 0;
646-
auto report = [&](const QString &shortCode, const QString &hex) {
646+
auto report = [&emojis](const QString &shortCode, const QString &hex) {
647647
if (auto opt_emoji = getUnicode(hex)) {
648648
for (const char32_t c : *opt_emoji) {
649649
if (isAsciiOrLatin1ControlCode(c)) {

src/group/groupwidget.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,9 @@ QVariant GroupModel::dataForCharacter(const SharedGroupChar &pCharacter,
532532
break;
533533

534534
case Qt::ToolTipRole: {
535-
const auto getRatioTooltip = [&](int numerator, int denomenator) -> QVariant {
535+
const auto getRatioTooltip =
536+
[&character, &column, &formatStat](const int numerator,
537+
const int denomenator) -> QVariant {
536538
if (character.getType() == CharacterTypeEnum::NPC) {
537539
return QVariant();
538540
} else {

src/group/mmapper2group.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ bool Mmapper2Group::updateChar(SharedGroupChar sharedCh, const JsonObj &obj)
312312
}
313313

314314
if (!ch.getColor().isValid()) {
315-
auto getColor = [&]() -> QColor {
315+
auto getColor = [this, &ch]() -> QColor {
316316
const auto &settings = getConfig().groupManager;
317317
if (ch.isNpc() && settings.npcColorOverride) {
318318
return settings.npcColor;

src/mainwindow/UpdateDialog.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,18 @@ namespace { // anonymous
2828
NODISCARD const char *getArchitectureRegexPattern()
2929
{
3030
// See Qt documentation for expected keys
31-
const std::array<std::pair<const char *, const char *>, 4> archPatterns = {
31+
static const std::array<std::pair<const char *, const char *>, 4> archPatterns = {
3232
{{"arm64", "(arm64|aarch64)"},
3333
{"x86_64", "(x86_64|amd64|x64)"},
3434
{"i386", "(i386|x86(?!_64))"},
3535
{"arm", "(arm(?!64)|armhf)"}}};
3636

37-
auto findPattern = [&](const QString &arch) -> const char * {
38-
auto it = std::find_if(archPatterns.begin(), archPatterns.end(), [&arch](const auto &pair) {
39-
return mmqt::toStdStringUtf8(arch) == pair.first;
40-
});
37+
static auto findPattern = [](const QString &arch) -> const char * {
38+
const auto it = std::find_if(archPatterns.begin(),
39+
archPatterns.end(),
40+
[&arch](const auto &pair) {
41+
return mmqt::toStdStringUtf8(arch) == pair.first;
42+
});
4143
return (it != archPatterns.end()) ? it->second : nullptr;
4244
};
4345

src/mainwindow/findroomsdlg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ void FindRoomsDlg::slot_findClicked()
147147
try {
148148
RoomFilter filter(text, cs, regex, kind);
149149
const Map &map = m_mapData.getCurrentMap();
150-
map.getRooms().for_each([&](const auto roomId) {
150+
map.getRooms().for_each([this, &filter, &map](const auto roomId) {
151151
const auto &room = map.getRoomHandle(roomId);
152152
if (!filter.filter(room.getRaw())) {
153153
return;

src/map/Map.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ void Map::printMulti(ProgressCounter &pc, AnsiOstream &os) const
351351

352352
std::set<ExternalRoomId> rooms;
353353
pc.setNewTask(ProgressMsg{"phase 1: scanning rooms"}, getRoomsCount());
354-
getRooms().for_each([&](const RoomId here) {
354+
getRooms().for_each([&pc, &rooms, &w](const RoomId here) {
355355
const auto &room = deref(w.getRoom(here));
356356
const auto hereExternal = w.convertToExternal(here);
357357
for (const ExitDirEnum dir : ALL_EXITS_NESWUD) {
@@ -443,7 +443,7 @@ void Map::printUnknown(ProgressCounter &pc, AnsiOstream &os) const
443443
{
444444
std::set<ExternalRoomId> set;
445445
pc.setNewTask(ProgressMsg{"scanning rooms"}, getRoomsCount());
446-
getRooms().for_each([&](const RoomId id) {
446+
getRooms().for_each([this, &pc, &set](const RoomId id) {
447447
const auto &room = getRoomHandle(id);
448448
if (!room.getExit(ExitDirEnum::UNKNOWN).outIsEmpty()
449449
|| !room.getExit(ExitDirEnum::UNKNOWN).inIsEmpty()) {
@@ -1184,7 +1184,7 @@ Map Map::merge(ProgressCounter &pc,
11841184
marks.reserve(currentMap.getMarksCount() + newMarks.size());
11851185

11861186
pc.setCurrentTask(ProgressMsg{"creating combined map: old rooms"});
1187-
currentMap.getRooms().for_each([&](const RoomId id) {
1187+
currentMap.getRooms().for_each([&currentMap, &pc, &rooms](const RoomId id) {
11881188
const RoomHandle &room = currentMap.getRoomHandle(id);
11891189
rooms.emplace_back(room.getRawCopyExternal());
11901190
pc.step();
@@ -1198,7 +1198,7 @@ Map Map::merge(ProgressCounter &pc,
11981198

11991199
pc.setCurrentTask(ProgressMsg{"creating combined map: old marks"});
12001200
const auto &db = currentMap.getInfomarkDb();
1201-
db.getIdSet().for_each([&](const auto id) {
1201+
db.getIdSet().for_each([&db, &marks, &pc](const auto id) {
12021202
marks.emplace_back(db.getRawCopy(id));
12031203
pc.step();
12041204
});
@@ -1233,7 +1233,7 @@ void Map::foreachChangedRoom(ProgressCounter &pc,
12331233
const std::function<void(const RawRoom &room)> &callback)
12341234
{
12351235
pc.increaseTotalStepsBy(current.getRoomsCount());
1236-
current.getRooms().for_each([&](const RoomId id) {
1236+
current.getRooms().for_each([&callback, &current, &pc, &saved](const RoomId id) {
12371237
const auto r = current.findRoomHandle(id);
12381238
if (!r) {
12391239
assert(false);

0 commit comments

Comments
 (0)