Create const overloads for begin() and end() in Instruction.
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 @@
// 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 @@
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<Instruction*>(inst)) {
+ for (const auto& operand : *inst) {
if (spvIsIdType(operand.type)) {
highest = std::max(highest, operand.words[0]);
}