From 6445703aa3106b67a69351c52d8ec3b0630d3d5b Mon Sep 17 00:00:00 2001 From: Thomas Alexander Date: Mon, 25 Mar 2024 20:19:06 -0300 Subject: [PATCH 1/2] Switch to iterator. --- include/qasm/AST/ASTBase.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/qasm/AST/ASTBase.h b/include/qasm/AST/ASTBase.h index e11dc49..cedc641 100644 --- a/include/qasm/AST/ASTBase.h +++ b/include/qasm/AST/ASTBase.h @@ -205,8 +205,8 @@ class ASTTokenFactory { if (MRI == TFM.rend()) return nullptr; - --MRI; - return MRI == TFM.rend() ? nullptr : (*MRI).second; + auto PrevMRI = std::prev(MRI); + return PrevMRI == TFM.rend() ? nullptr : (*PrevMRI).second; } static uint32_t GetCurrentIndex() { return TIX; } From 1f41c3d3f980d8f3c15062233be7d800f95486f8 Mon Sep 17 00:00:00 2001 From: Thomas Alexander Date: Mon, 25 Mar 2024 20:59:05 -0300 Subject: [PATCH 2/2] Change iteration behaviour. --- include/qasm/AST/ASTBase.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/include/qasm/AST/ASTBase.h b/include/qasm/AST/ASTBase.h index cedc641..4f4689e 100644 --- a/include/qasm/AST/ASTBase.h +++ b/include/qasm/AST/ASTBase.h @@ -201,12 +201,10 @@ class ASTTokenFactory { } static const ASTToken *GetPreviousToken() { - std::map::const_reverse_iterator MRI = TFM.rbegin(); - if (MRI == TFM.rend()) + if (TFM.empty()) return nullptr; - auto PrevMRI = std::prev(MRI); - return PrevMRI == TFM.rend() ? nullptr : (*PrevMRI).second; + return std::prev(TFM.end())->second; } static uint32_t GetCurrentIndex() { return TIX; }