From b1b2cac2cfc40e33ae12ce9f8b869febb78e5ce5 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Fri, 26 Aug 2016 16:52:16 -0400 Subject: [PATCH] Create const overloads for begin() and end() in Instruction. --- source/opt/instruction.h | 2 ++ source/opt/module.cpp | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/source/opt/instruction.h b/source/opt/instruction.h index 5e6043a..5750d97 100644 --- a/source/opt/instruction.h +++ b/source/opt/instruction.h @@ -123,6 +123,8 @@ class Instruction { // Begin and end iterators for operands. iterator begin() { return operands_.begin(); } iterator end() { return operands_.end(); } + const_iterator begin() const { return operands_.cbegin(); } + const_iterator end() const { return operands_.cend(); } // Const begin and end iterators for operands. const_iterator cbegin() const { return operands_.cbegin(); } const_iterator cend() const { return operands_.cend(); } diff --git a/source/opt/module.cpp b/source/opt/module.cpp index 204bd96..0846012 100644 --- a/source/opt/module.cpp +++ b/source/opt/module.cpp @@ -126,8 +126,7 @@ uint32_t Module::ComputeIdBound() const { ForEachInst( [&highest](const Instruction* inst) { - // Use a const-cast just to access begin() and end() for the range-for. - for (const auto& operand : *const_cast(inst)) { + for (const auto& operand : *inst) { if (spvIsIdType(operand.type)) { highest = std::max(highest, operand.words[0]); } -- 2.7.4