diff --git a/src/common/intrusive_list.h b/src/common/intrusive_list.h index 021eea05..c7b402e7 100644 --- a/src/common/intrusive_list.h +++ b/src/common/intrusive_list.h @@ -216,6 +216,14 @@ public: return root->next == root.get(); } + /** + * Gets the total number of elements within this list. + * @return the number of elements in this list. + */ + size_type size() const { + return static_cast(std::distance(begin(), end())); + } + /** * Retrieves a reference to the node at the front of the list. * @note Must not be called on an empty list. diff --git a/src/frontend/ir/basic_block.h b/src/frontend/ir/basic_block.h index 2fd6d385..006a2319 100644 --- a/src/frontend/ir/basic_block.h +++ b/src/frontend/ir/basic_block.h @@ -30,6 +30,7 @@ namespace IR { class Block final { public: using InstructionList = Common::IntrusiveList; + using size_type = InstructionList::size_type; using iterator = InstructionList::iterator; using const_iterator = InstructionList::const_iterator; using reverse_iterator = InstructionList::reverse_iterator; @@ -38,6 +39,7 @@ public: explicit Block(const Arm::LocationDescriptor& location) : location(location) {} bool empty() const { return instructions.empty(); } + size_type size() const { return instructions.size(); } Inst& front() { return instructions.front(); } const Inst& front() const { return instructions.front(); }