From b63cd06ca2a958c7742f11c4c80865d17f3656ac Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Tue, 23 Feb 2021 12:17:51 -0700 Subject: [PATCH] 3751: Convert for loops with pairs to structured bindings (#3752) * 3751: convert for loops with pairs to structured bindings * 3751: disable gcc7 unused variable warning - it warns about structured bindings * 3751: also add -Wno-unused-variable to lib/kdl * 3751: fix typo --- cmake/Utils.cmake | 5 +++++ common/src/Assets/EntityModelManager.cpp | 3 +-- common/src/EL/Expression.cpp | 3 +-- common/src/EL/Value.cpp | 6 +++--- common/src/IO/ImageFileSystem.cpp | 8 +++---- common/src/IO/MapReader.cpp | 5 +---- common/src/IO/Parser.h | 4 +--- common/src/Model/ModelUtils.cpp | 11 +++++----- common/src/Model/Polyhedron_Matcher.h | 5 +---- common/src/Renderer/EntityModelRenderer.cpp | 5 +---- common/src/Renderer/FaceRenderer.cpp | 3 +-- common/src/Renderer/PointHandleRenderer.cpp | 7 +++---- common/src/Renderer/PrimitiveRenderer.cpp | 16 ++++---------- common/src/Renderer/TexturedIndexRangeMap.cpp | 17 ++++----------- common/src/View/BrushVertexCommands.cpp | 4 ++-- common/src/View/ClipTool.cpp | 3 +-- common/src/View/EntityBrowserView.cpp | 4 +--- common/src/View/EntityPropertyEditor.cpp | 4 ++-- common/src/View/MapDocument.cpp | 17 ++++++--------- common/src/View/MapDocumentCommandFacade.cpp | 21 +++++-------------- common/src/View/MapFrame.cpp | 8 +++---- .../src/View/SmartPropertyEditorManager.cpp | 5 ++--- common/src/View/TextureBrowserView.cpp | 9 ++------ common/src/View/VertexHandleManager.cpp | 16 +++++--------- common/src/View/VertexHandleManager.h | 20 ++++++++---------- lib/kdl/CMakeLists.txt | 5 +++++ lib/kdl/include/kdl/map_utils.h | 12 +++++------ 27 files changed, 85 insertions(+), 141 deletions(-) diff --git a/cmake/Utils.cmake b/cmake/Utils.cmake index 1c42d05a3d..fdc3f66f65 100644 --- a/cmake/Utils.cmake +++ b/cmake/Utils.cmake @@ -113,6 +113,11 @@ macro(set_compiler_config TARGET) # FIXME: enable -Wcpp once we found a workaround for glew / QOpenGLWindow problem, see RenderView.h target_compile_options(${TARGET} PRIVATE -Wno-cpp) + + # gcc <= 7 warns about unused structured bindings, see https://github.com/TrenchBroom/TrenchBroom/issues/3751 + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8) + target_compile_options(${TARGET} PRIVATE -Wno-unused-variable) + endif() elseif(COMPILER_IS_MSVC) target_compile_definitions(${TARGET} PRIVATE _CRT_SECURE_NO_DEPRECATE _CRT_NONSTDC_NO_DEPRECATE) target_compile_options(${TARGET} PRIVATE /W4 /EHsc /MP) diff --git a/common/src/Assets/EntityModelManager.cpp b/common/src/Assets/EntityModelManager.cpp index 7607c8363f..188e0d39d6 100644 --- a/common/src/Assets/EntityModelManager.cpp +++ b/common/src/Assets/EntityModelManager.cpp @@ -172,8 +172,7 @@ namespace TrenchBroom { void EntityModelManager::resetTextureMode() { if (m_resetTextureMode) { - for (const auto& entry : m_models) { - auto& model = entry.second; + for (const auto& [path, model] : m_models) { model->setTextureMode(m_minFilter, m_magFilter); } m_resetTextureMode = false; diff --git a/common/src/EL/Expression.cpp b/common/src/EL/Expression.cpp index 329743da8d..5e7deb0297 100644 --- a/common/src/EL/Expression.cpp +++ b/common/src/EL/Expression.cpp @@ -280,8 +280,7 @@ namespace TrenchBroom { std::optional MapExpression::optimize() { bool allOptimized = true; - for (auto& entry : m_elements) { - auto& expression = entry.second; + for (auto& [key, expression] : m_elements) { allOptimized &= expression.optimize(); } diff --git a/common/src/EL/Value.cpp b/common/src/EL/Value.cpp index a48f4b003c..534107965d 100644 --- a/common/src/EL/Value.cpp +++ b/common/src/EL/Value.cpp @@ -640,9 +640,9 @@ namespace TrenchBroom { } size_t i = 0; - for (const auto& entry : m) { - str << childIndent << "\"" << entry.first << "\"" << ": "; - entry.second.appendToStream(str, multiline, childIndent); + for (const auto& [key, value] : m) { + str << childIndent << "\"" << key << "\"" << ": "; + value.appendToStream(str, multiline, childIndent); if (i++ < m.size() - 1) { str << ","; if (!multiline) { diff --git a/common/src/IO/ImageFileSystem.cpp b/common/src/IO/ImageFileSystem.cpp index 304f745b99..a49d425cb0 100644 --- a/common/src/IO/ImageFileSystem.cpp +++ b/common/src/IO/ImageFileSystem.cpp @@ -132,12 +132,12 @@ namespace TrenchBroom { std::vector ImageFileSystemBase::Directory::contents() const { std::vector contents; - for (const auto& entry : m_directories) { - contents.push_back(Path(entry.first)); + for (const auto& [path, directory] : m_directories) { + contents.push_back(Path(path)); } - for (const auto& entry : m_files) { - contents.push_back(Path(entry.first)); + for (const auto& [path, file] : m_files) { + contents.push_back(Path(path)); } return contents; diff --git a/common/src/IO/MapReader.cpp b/common/src/IO/MapReader.cpp index c240a2e222..2e598033dc 100644 --- a/common/src/IO/MapReader.cpp +++ b/common/src/IO/MapReader.cpp @@ -401,10 +401,7 @@ namespace TrenchBroom { * Resolves cases when a child is parsed before its parent; called after the whole map is parsed. */ void MapReader::resolveNodes(ParserStatus& status) { - for (const auto& entry : m_unresolvedNodes) { - Model::Node* node = entry.first; - const ParentInfo& info = entry.second; - + for (const auto& [node, info] : m_unresolvedNodes) { Model::Node* parent = resolveParent(info); if (parent == nullptr) onUnresolvedNode(info, node, status); diff --git a/common/src/IO/Parser.h b/common/src/IO/Parser.h index cd758af732..9f2a971796 100644 --- a/common/src/IO/Parser.h +++ b/common/src/IO/Parser.h @@ -89,9 +89,7 @@ namespace TrenchBroom { m_tokenNames = tokenNames(); std::vector names; - for (const auto& entry : m_tokenNames) { - const TokenType type = entry.first; - const std::string& name = entry.second; + for (const auto& [type, name] : m_tokenNames) { if ((typeMask & type) != 0) names.push_back(name); } diff --git a/common/src/Model/ModelUtils.cpp b/common/src/Model/ModelUtils.cpp index ced1f64282..bbff09bddc 100644 --- a/common/src/Model/ModelUtils.cpp +++ b/common/src/Model/ModelUtils.cpp @@ -148,8 +148,7 @@ namespace TrenchBroom { template static std::vector doCollectParents(const T& nodes) { std::vector result; - for (const auto& entry : nodes) { - Node* parent = entry.first; + for (const auto& [parent, children] : nodes) { collectWithParents(parent, result); } return kdl::vec_sort_and_remove_duplicates(std::move(result)); @@ -165,16 +164,16 @@ namespace TrenchBroom { std::vector collectChildren(const std::map>& nodes) { std::vector result; - for (const auto& entry : nodes) { - result = kdl::vec_concat(std::move(result), entry.second); + for (const auto& [parent, children] : nodes) { + result = kdl::vec_concat(std::move(result), children); } return result; } std::vector collectChildren(const std::vector>>>& nodes) { std::vector result; - for (const auto& entry : nodes) { - result = kdl::vec_concat(std::move(result), kdl::vec_transform(entry.second, [](auto& child) { return child.get(); })); + for (const auto& [parent, children] : nodes) { + result = kdl::vec_concat(std::move(result), kdl::vec_transform(children, [](auto& child) { return child.get(); })); } return result; } diff --git a/common/src/Model/Polyhedron_Matcher.h b/common/src/Model/Polyhedron_Matcher.h index 43752605de..4d4fa77606 100644 --- a/common/src/Model/Polyhedron_Matcher.h +++ b/common/src/Model/Polyhedron_Matcher.h @@ -303,10 +303,7 @@ namespace TrenchBroom { static VertexRelation buildVertexRelation(const P& left, const P& right, const VMap& vertexMap) { VertexRelation result; - for (const auto& entry : vertexMap) { - const auto& leftPosition = entry.first; - const auto& rightPosition = entry.second; - + for (const auto& [leftPosition, rightPosition] : vertexMap) { auto* leftVertex = left.findVertexByPosition(leftPosition); auto* rightVertex = right.findVertexByPosition(rightPosition); diff --git a/common/src/Renderer/EntityModelRenderer.cpp b/common/src/Renderer/EntityModelRenderer.cpp index 800c0e198f..a3cbd9df04 100644 --- a/common/src/Renderer/EntityModelRenderer.cpp +++ b/common/src/Renderer/EntityModelRenderer.cpp @@ -143,14 +143,11 @@ namespace TrenchBroom { glAssert(glEnable(GL_TEXTURE_2D)); glAssert(glActiveTexture(GL_TEXTURE0)); - for (const auto& entry : m_entities) { - auto* entityNode = entry.first; + for (const auto& [entityNode, renderer] : m_entities) { if (!m_showHiddenEntities && !m_editorContext.visible(entityNode)) { continue; } - auto* renderer = entry.second; - const auto transformation = entityNode->entity().modelTransformation(); MultiplyModelMatrix multMatrix(renderContext.transformation(), vm::mat4x4f(transformation)); diff --git a/common/src/Renderer/FaceRenderer.cpp b/common/src/Renderer/FaceRenderer.cpp index 77a5203fdb..d120313820 100644 --- a/common/src/Renderer/FaceRenderer.cpp +++ b/common/src/Renderer/FaceRenderer.cpp @@ -125,8 +125,7 @@ namespace TrenchBroom { void FaceRenderer::prepareVerticesAndIndices(VboManager& vboManager) { m_vertexArray->prepare(vboManager); - for (const auto& pair : *m_indexArrayMap) { - const auto& brushIndexHolderPtr = pair.second; + for (const auto& [texture, brushIndexHolderPtr] : *m_indexArrayMap) { brushIndexHolderPtr->prepare(vboManager); } } diff --git a/common/src/Renderer/PointHandleRenderer.cpp b/common/src/Renderer/PointHandleRenderer.cpp index 447aa9f984..9415b94a4a 100644 --- a/common/src/Renderer/PointHandleRenderer.cpp +++ b/common/src/Renderer/PointHandleRenderer.cpp @@ -88,11 +88,10 @@ namespace TrenchBroom { const Camera& camera = renderContext.camera(); ActiveShader shader(renderContext.shaderManager(), Shaders::HandleShader); - for (const auto& entry : map) { - const Color color = mixAlpha(entry.first, opacity); - shader.set("Color", color); + for (const auto& [color, positions] : map) { + shader.set("Color", mixAlpha(color, opacity)); - for (const vm::vec3f& position : entry.second) { + for (const vm::vec3f& position : positions) { vm::vec3f nudgeTowardsCamera; // In 3D view, nudge towards camera by the handle radius, to prevent lines (brush edges, etc.) from clipping into the handle diff --git a/common/src/Renderer/PrimitiveRenderer.cpp b/common/src/Renderer/PrimitiveRenderer.cpp index ec63e4af51..a98b999ab7 100644 --- a/common/src/Renderer/PrimitiveRenderer.cpp +++ b/common/src/Renderer/PrimitiveRenderer.cpp @@ -246,18 +246,14 @@ namespace TrenchBroom { } void PrimitiveRenderer::prepareLines(VboManager& vboManager) { - for (auto& entry : m_lineMeshes) { - const LineRenderAttributes& attributes = entry.first; - IndexRangeMapBuilder& mesh = entry.second; + for (auto& [attributes, mesh] : m_lineMeshes) { IndexRangeRenderer& renderer = m_lineMeshRenderers.insert(std::make_pair(attributes, IndexRangeRenderer(mesh))).first->second; renderer.prepare(vboManager); } } void PrimitiveRenderer::prepareTriangles(VboManager& vboManager) { - for (auto& entry : m_triangleMeshes) { - const TriangleRenderAttributes& attributes = entry.first; - IndexRangeMapBuilder& mesh = entry.second; + for (auto& [attributes, mesh] : m_triangleMeshes) { IndexRangeRenderer& renderer = m_triangleMeshRenderers.insert(std::make_pair(attributes, IndexRangeRenderer(mesh))).first->second; renderer.prepare(vboManager); } @@ -271,9 +267,7 @@ namespace TrenchBroom { void PrimitiveRenderer::renderLines(RenderContext& renderContext) { ActiveShader shader(renderContext.shaderManager(), Shaders::VaryingPUniformCShader); - for (auto& entry : m_lineMeshRenderers) { - const LineRenderAttributes& attributes = entry.first; - IndexRangeRenderer& renderer = entry.second; + for (auto& [attributes, renderer] : m_lineMeshRenderers) { attributes.render(renderer, shader); } glAssert(glLineWidth(1.0f)) @@ -282,9 +276,7 @@ namespace TrenchBroom { void PrimitiveRenderer::renderTriangles(RenderContext& renderContext) { ActiveShader shader(renderContext.shaderManager(), Shaders::VaryingPUniformCShader); - for (auto& entry : m_triangleMeshRenderers) { - const TriangleRenderAttributes& attributes = entry.first; - IndexRangeRenderer& renderer = entry.second; + for (auto& [attributes, renderer] : m_triangleMeshRenderers) { attributes.render(renderer, shader); } } diff --git a/common/src/Renderer/TexturedIndexRangeMap.cpp b/common/src/Renderer/TexturedIndexRangeMap.cpp index dc8f89b034..b14f3c809c 100644 --- a/common/src/Renderer/TexturedIndexRangeMap.cpp +++ b/common/src/Renderer/TexturedIndexRangeMap.cpp @@ -34,9 +34,7 @@ namespace TrenchBroom { } void TexturedIndexRangeMap::Size::inc(const TexturedIndexRangeMap::Size& other) { - for (const auto& entry : other.m_sizes) { - auto* texture = entry.first; - const auto& indexRange = entry.second; + for (const auto& [texture, indexRange] : other.m_sizes) { auto& sizeForKey = findCurrent(texture); sizeForKey.inc(indexRange); } @@ -61,9 +59,7 @@ namespace TrenchBroom { } void TexturedIndexRangeMap::Size::initialize(TextureToIndexRangeMap& data) const { - for (const auto& entry : m_sizes) { - const auto* texture = entry.first; - const auto& size = entry.second; + for (const auto& [texture, size] : m_sizes) { data.insert(std::make_pair(texture, IndexRangeMap(size))); } } @@ -100,9 +96,7 @@ namespace TrenchBroom { } void TexturedIndexRangeMap::add(const TexturedIndexRangeMap& other) { - for (const auto& entry : *other.m_data) { - auto* texture = entry.first; - const auto& indexRangeMap = entry.second; + for (const auto& [texture, indexRangeMap] : *other.m_data) { auto& current = findCurrent(texture); current.add(indexRangeMap); } @@ -114,10 +108,7 @@ namespace TrenchBroom { } void TexturedIndexRangeMap::render(VertexArray& vertexArray, TextureRenderFunc& func) { - for (const auto& entry : *m_data) { - const auto* texture = entry.first; - const auto& indexArray = entry.second; - + for (const auto& [texture, indexArray] : *m_data) { func.before(texture); indexArray.render(vertexArray); func.after(texture); diff --git a/common/src/View/BrushVertexCommands.cpp b/common/src/View/BrushVertexCommands.cpp index 2f536ddb76..23553425d0 100644 --- a/common/src/View/BrushVertexCommands.cpp +++ b/common/src/View/BrushVertexCommands.cpp @@ -39,8 +39,8 @@ namespace TrenchBroom { static auto collectBrushNodes(const std::vector> nodes) { auto result = std::vector{}; - for (const auto& pair : nodes) { - if (auto* brushNode = dynamic_cast(pair.first)) { + for (const auto& [node, contents] : nodes) { + if (auto* brushNode = dynamic_cast(node)) { result.push_back(brushNode); } } diff --git a/common/src/View/ClipTool.cpp b/common/src/View/ClipTool.cpp index bc915da101..f976883cfa 100644 --- a/common/src/View/ClipTool.cpp +++ b/common/src/View/ClipTool.cpp @@ -827,8 +827,7 @@ namespace TrenchBroom { void ClipTool::addBrushesToRenderer(const std::map>& map, Renderer::BrushRenderer& renderer) { std::vector brushes; - for (const auto& entry : map) { - const auto& nodes = entry.second; + for (const auto& [parent, nodes] : map) { for (auto* node : nodes) { node->accept(kdl::overload( [] (const Model::WorldNode*) {}, diff --git a/common/src/View/EntityBrowserView.cpp b/common/src/View/EntityBrowserView.cpp index 08940723fc..73fbd2675f 100644 --- a/common/src/View/EntityBrowserView.cpp +++ b/common/src/View/EntityBrowserView.cpp @@ -368,9 +368,7 @@ namespace TrenchBroom { { // create and upload all vertex arrays const auto stringVertices = collectStringVertices(layout, y, height); - for (const auto& entry : stringVertices) { - const auto& fontDescriptor = entry.first; - const auto& vertices = entry.second; + for (const auto& [fontDescriptor, vertices] : stringVertices) { stringRenderers[fontDescriptor] = Renderer::VertexArray::ref(vertices); stringRenderers[fontDescriptor].prepare(vboManager()); } diff --git a/common/src/View/EntityPropertyEditor.cpp b/common/src/View/EntityPropertyEditor.cpp index 2fb277b819..3061715c0a 100644 --- a/common/src/View/EntityPropertyEditor.cpp +++ b/common/src/View/EntityPropertyEditor.cpp @@ -146,8 +146,8 @@ namespace TrenchBroom { // Concatenate the flag descriptions and return. QString result; QTextStream stream(&result); - for (const auto& flagDescriptor : flagDescriptors) { - stream << flagDescriptor.second << "\n"; + for (const auto& [value, description] : flagDescriptors) { + stream << description << "\n"; } return result; } diff --git a/common/src/View/MapDocument.cpp b/common/src/View/MapDocument.cpp index 6c2e6a8430..7865e2001b 100644 --- a/common/src/View/MapDocument.cpp +++ b/common/src/View/MapDocument.cpp @@ -1039,8 +1039,8 @@ namespace TrenchBroom { std::vector getLinkedGroupIdsRecursively(const std::map>& parentChildrenMap) { std::vector linkedGroupIds; - for (const auto& pair : parentChildrenMap) { - Model::Node::visitAll(pair.second, kdl::overload( + for (const auto& [parent, children] : parentChildrenMap) { + Model::Node::visitAll(children, kdl::overload( [] (auto&& thisLambda, const Model::WorldNode* worldNode) { worldNode->visitChildren(thisLambda); }, [] (auto&& thisLambda, const Model::LayerNode* layerNode) { layerNode->visitChildren(thisLambda); }, [&](auto&& thisLambda, const Model::GroupNode* groupNode) { @@ -1089,8 +1089,7 @@ namespace TrenchBroom { std::map> MapDocument::collectRemovableParents(const std::map>& nodes) const { std::map> result; - for (const auto& entry : nodes) { - Model::Node* node = entry.first; + for (const auto& [node, children] : nodes) { if (node->removeIfEmpty() && !node->hasChildren()) { Model::Node* parent = node->parent(); ensure(parent != nullptr, "parent is null"); @@ -1126,8 +1125,7 @@ namespace TrenchBroom { } void MapDocument::closeRemovedGroups(const std::map>& toRemove) { - for (const auto& entry : toRemove) { - const std::vector& nodes = entry.second; + for (const auto& [parent, nodes] : toRemove) { for (const Model::Node* node : nodes) { if (node == currentGroup()) { closeGroup(); @@ -1143,8 +1141,7 @@ namespace TrenchBroom { return false; std::map> nodesToRemove; - for (const auto& entry : nodesToAdd) { - const std::vector& children = entry.second; + for (const auto& [newParent, children] : nodesToAdd) { nodesToRemove = kdl::map_merge(nodesToRemove, Model::parentChildrenMap(children)); } @@ -1181,9 +1178,7 @@ namespace TrenchBroom { } bool MapDocument::checkReparenting(const std::map>& nodesToAdd) const { - for (const auto& entry : nodesToAdd) { - const Model::Node* newParent = entry.first; - const std::vector& children = entry.second; + for (const auto& [newParent, children] : nodesToAdd) { if (!newParent->canAddChildren(std::begin(children), std::end(children))) return false; } diff --git a/common/src/View/MapDocumentCommandFacade.cpp b/common/src/View/MapDocumentCommandFacade.cpp index c8be6210b0..c44d98d0cc 100644 --- a/common/src/View/MapDocumentCommandFacade.cpp +++ b/common/src/View/MapDocumentCommandFacade.cpp @@ -231,9 +231,7 @@ namespace TrenchBroom { Notifier&>::NotifyBeforeAndAfter notifyParents(nodesWillChangeNotifier, nodesDidChangeNotifier, parents); std::vector addedNodes; - for (const auto& entry : nodes) { - Model::Node* parent = entry.first; - const std::vector& children = entry.second; + for (const auto& [parent, children] : nodes) { parent->addChildren(children); addedNodes = kdl::vec_concat(std::move(addedNodes), children); } @@ -253,9 +251,7 @@ namespace TrenchBroom { const std::vector allChildren = collectChildren(nodes); Notifier&>::NotifyBeforeAndAfter notifyChildren(nodesWillBeRemovedNotifier, nodesWereRemovedNotifier, allChildren); - for (const auto& entry : nodes) { - Model::Node* parent = entry.first; - const std::vector& children = entry.second; + for (const auto& [parent, children] : nodes) { unsetEntityModels(children); unsetEntityDefinitions(children); unsetTextures(children); @@ -276,10 +272,7 @@ namespace TrenchBroom { auto allOldChildren = std::vector{}; auto allNewChildren = std::vector{}; - for (auto& entry : nodes) { - Model::Node* parent = entry.first; - - auto& newChildren = entry.second; + for (auto& [parent, newChildren] : nodes) { allNewChildren = kdl::vec_concat(std::move(allNewChildren), kdl::vec_transform(newChildren, [](auto& child) { return child.get(); })); auto oldChildren = parent->replaceChildren(std::move(newChildren)); @@ -406,9 +399,7 @@ namespace TrenchBroom { std::vector changedNodes; changedNodes.reserve(nodes.size()); - for (const auto& entry : nodes) { - Model::Node* node = entry.first; - const Model::VisibilityState state = entry.second; + for (const auto& [node, state] : nodes) { if (node->setVisibilityState(state)) changedNodes.push_back(node); } @@ -438,9 +429,7 @@ namespace TrenchBroom { std::vector changedNodes; changedNodes.reserve(nodes.size()); - for (const auto& entry : nodes) { - Model::Node* node = entry.first; - const Model::LockState state = entry.second; + for (const auto& [node, state] : nodes) { if (node->setLockState(state)) changedNodes.push_back(node); } diff --git a/common/src/View/MapFrame.cpp b/common/src/View/MapFrame.cpp index 48265115bb..f03f97cd33 100644 --- a/common/src/View/MapFrame.cpp +++ b/common/src/View/MapFrame.cpp @@ -1895,13 +1895,13 @@ namespace TrenchBroom { }; QStringList verticalHeaderLabels; - for (const auto& role : roles) { - verticalHeaderLabels.append(role.second); + for (const auto& [role, roleLabel] : roles) { + verticalHeaderLabels.append(roleLabel); } QStringList horizontalHeaderLabels; - for (const auto& group : groups) { - horizontalHeaderLabels.append(group.second); + for (const auto& [group, groupLabel] : groups) { + horizontalHeaderLabels.append(groupLabel); } auto* table = new QTableWidget(static_cast(roles.size()), diff --git a/common/src/View/SmartPropertyEditorManager.cpp b/common/src/View/SmartPropertyEditorManager.cpp index bdd826a948..0347d2f9f5 100644 --- a/common/src/View/SmartPropertyEditorManager.cpp +++ b/common/src/View/SmartPropertyEditorManager.cpp @@ -110,10 +110,9 @@ namespace TrenchBroom { } SmartPropertyEditorManager::EditorPtr SmartPropertyEditorManager::selectEditor(const std::string& propertyKey, const std::vector& nodes) const { - for (const auto& entry : m_editors) { - const MatcherPtr matcher = entry.first; + for (const auto& [matcher, editor] : m_editors) { if (matcher->matches(propertyKey, nodes)) - return entry.second; + return editor; } // should never happen diff --git a/common/src/View/TextureBrowserView.cpp b/common/src/View/TextureBrowserView.cpp index a75b82e3b8..bce68a75de 100644 --- a/common/src/View/TextureBrowserView.cpp +++ b/common/src/View/TextureBrowserView.cpp @@ -428,9 +428,7 @@ namespace TrenchBroom { using StringRendererMap = std::map; StringRendererMap stringRenderers; - for (const auto& entry : collectStringVertices(layout, y, height)) { - const auto& descriptor = entry.first; - const auto& vertices = entry.second; + for (const auto& [descriptor, vertices] : collectStringVertices(layout, y, height)) { stringRenderers[descriptor] = Renderer::VertexArray::ref(vertices); stringRenderers[descriptor].prepare(vboManager()); } @@ -438,10 +436,7 @@ namespace TrenchBroom { Renderer::ActiveShader shader(shaderManager(), Renderer::Shaders::ColoredTextShader); shader.set("Texture", 0); - for (auto& entry : stringRenderers) { - const auto& descriptor = entry.first; - auto& vertexArray = entry.second; - + for (auto& [descriptor, vertexArray] : stringRenderers) { auto& font = fontManager().font(descriptor); font.activate(); vertexArray.render(Renderer::PrimType::Quads); diff --git a/common/src/View/VertexHandleManager.cpp b/common/src/View/VertexHandleManager.cpp index cd247616dd..7a029b3b6e 100644 --- a/common/src/View/VertexHandleManager.cpp +++ b/common/src/View/VertexHandleManager.cpp @@ -38,8 +38,7 @@ namespace TrenchBroom { const Model::HitType::Type VertexHandleManager::HandleHitType = Model::HitType::freeType(); void VertexHandleManager::pick(const vm::ray3& pickRay, const Renderer::Camera& camera, Model::PickResult& pickResult) const { - for (const auto& entry : m_handles) { - const auto& position = entry.first; + for (const auto& [position, info] : m_handles) { const auto distance = camera.pickPointHandle(pickRay, position, static_cast(pref(Preferences::HandleRadius))); if (!vm::is_nan(distance)) { const auto hitPoint = vm::point_at_distance(pickRay, distance); @@ -75,8 +74,7 @@ namespace TrenchBroom { const Model::HitType::Type EdgeHandleManager::HandleHitType = Model::HitType::freeType(); void EdgeHandleManager::pickGridHandle(const vm::ray3& pickRay, const Renderer::Camera& camera, const Grid& grid, Model::PickResult& pickResult) const { - for (const HandleEntry& entry : m_handles) { - const vm::segment3& position = entry.first; + for (const auto& [position, info] : m_handles) { const FloatType edgeDist = camera.pickLineSegmentHandle(pickRay, position, static_cast(pref(Preferences::HandleRadius))); if (!vm::is_nan(edgeDist)) { const vm::vec3 pointHandle = grid.snap(vm::point_at_distance(pickRay, edgeDist), position); @@ -90,8 +88,7 @@ namespace TrenchBroom { } void EdgeHandleManager::pickCenterHandle(const vm::ray3& pickRay, const Renderer::Camera& camera, Model::PickResult& pickResult) const { - for (const HandleEntry& entry : m_handles) { - const vm::segment3& position = entry.first; + for (const auto& [position, info] : m_handles) { const vm::vec3 pointHandle = position.center(); const FloatType pointDist = camera.pickPointHandle(pickRay, pointHandle, static_cast(pref(Preferences::HandleRadius))); @@ -128,9 +125,7 @@ namespace TrenchBroom { const Model::HitType::Type FaceHandleManager::HandleHitType = Model::HitType::freeType(); void FaceHandleManager::pickGridHandle(const vm::ray3& pickRay, const Renderer::Camera& camera, const Grid& grid, Model::PickResult& pickResult) const { - for (const auto& entry : m_handles) { - const auto& position = entry.first; - + for (const auto& [position, info] : m_handles) { const auto [valid, plane] = vm::from_points(std::begin(position), std::end(position)); if (!valid) { continue; @@ -150,8 +145,7 @@ namespace TrenchBroom { } void FaceHandleManager::pickCenterHandle(const vm::ray3& pickRay, const Renderer::Camera& camera, Model::PickResult& pickResult) const { - for (const HandleEntry& entry : m_handles) { - const auto& position = entry.first; + for (const auto& [position, info] : m_handles) { const auto pointHandle = position.center(); const auto pointDist = camera.pickPointHandle(pickRay, pointHandle, static_cast(pref(Preferences::HandleRadius))); diff --git a/common/src/View/VertexHandleManager.h b/common/src/View/VertexHandleManager.h index e2827b97ce..8fbe8dab71 100644 --- a/common/src/View/VertexHandleManager.h +++ b/common/src/View/VertexHandleManager.h @@ -247,9 +247,7 @@ namespace TrenchBroom { private: template void collectHandles(const T& test, O out) const { - for (const HandleEntry& entry : m_handles) { - const Handle& handle = entry.first; - const HandleInfo& info = entry.second; + for (const auto& [handle, info] : m_handles) { if (test(info)) { out++ = handle; } @@ -389,8 +387,8 @@ namespace TrenchBroom { * Deselects all currently selected handles */ void deselectAll() { - for (auto& entry : m_handles) { - deselect(entry.second); + for (auto& [handle, info] : m_handles) { + deselect(info); } } @@ -420,11 +418,11 @@ namespace TrenchBroom { } private: template - void forEachCloseHandle(const H& handle, F fun) { + void forEachCloseHandle(const H& otherHandle, F fun) { static const auto epsilon = 0.001 * 0.001; - for (auto& entry : m_handles) { - if (compare(handle, entry.first, epsilon) == 0) { - fun(entry.second); + for (auto& [handle, info] : m_handles) { + if (compare(otherHandle, handle, epsilon) == 0) { + fun(info); } } } @@ -463,8 +461,8 @@ namespace TrenchBroom { */ template void pick(const P& test, Model::PickResult& pickResult) const { - for (const auto& entry : m_handles) { - const auto hit = test(entry.first); + for (const auto& [handle, info] : m_handles) { + const auto hit = test(handle); if (hit.isMatch()) { pickResult.addHit(hit); } diff --git a/lib/kdl/CMakeLists.txt b/lib/kdl/CMakeLists.txt index 69a9ed7b9b..4d9db47860 100644 --- a/lib/kdl/CMakeLists.txt +++ b/lib/kdl/CMakeLists.txt @@ -60,6 +60,11 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "App target_compile_options(kdl INTERFACE -Wall -Wextra -Wconversion -Wshadow-all -pedantic -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wno-exit-time-destructors) elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") target_compile_options(kdl INTERFACE -Wall -Wextra -Wconversion -Wshadow=local -pedantic) + + # gcc <= 7 warns about unused structured bindings, see https://github.com/TrenchBroom/TrenchBroom/issues/3751 + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8) + target_compile_options(kdl INTERFACE -Wno-unused-variable) + endif() elseif(MSVC EQUAL 1) target_compile_options(kdl INTERFACE /W4 /EHsc /MP) diff --git a/lib/kdl/include/kdl/map_utils.h b/lib/kdl/include/kdl/map_utils.h index c2e29ffb71..283f589d6b 100644 --- a/lib/kdl/include/kdl/map_utils.h +++ b/lib/kdl/include/kdl/map_utils.h @@ -36,8 +36,8 @@ namespace kdl { std::vector map_keys(const std::map& m) { std::vector result; result.reserve(m.size()); - for (const auto& e : m) { - result.push_back(e.first); + for (const auto& [key, value] : m) { + result.push_back(key); } return result; } @@ -55,8 +55,8 @@ namespace kdl { std::vector map_values(const std::map& m) { std::vector result; result.reserve(m.size()); - for (const auto& e : m) { - result.push_back(e.second); + for (const auto& [key, value] : m) { + result.push_back(value); } return result; } @@ -208,8 +208,8 @@ namespace kdl { */ template> void map_clear_and_delete(std::map>& m, const D& deleter = D()) { - for (auto& e : m) { - kdl::col_delete_all(e.second, deleter); + for (auto& [key, value] : m) { + kdl::col_delete_all(value, deleter); } m.clear(); }