diff --git a/source/opt/iterator.h b/source/opt/iterator.h index bb52171fc..4ee1e400b 100644 --- a/source/opt/iterator.h +++ b/source/opt/iterator.h @@ -105,6 +105,24 @@ class IteratorRange { IteratorType end_; }; +// Returns a (begin, end) iterator pair for the given container. +template > +inline IteratorRange make_range( + std::vector>& container) { + return {IteratorType(&container, container.begin()), + IteratorType(&container, container.end())}; +} + +// Returns a const (begin, end) iterator pair for the given container. +template > +inline IteratorRange make_const_range( + const std::vector>& container) { + return {IteratorType(&container, container.cbegin()), + IteratorType(&container, container.cend())}; +} + template inline UptrVectorIterator& UptrVectorIterator::operator++() { ++iterator_; diff --git a/source/opt/module.h b/source/opt/module.h index f34c9117b..1aee9127c 100644 --- a/source/opt/module.h +++ b/source/opt/module.h @@ -198,26 +198,19 @@ inline Module::inst_iterator Module::debug_end() { } inline IteratorRange Module::debugs() { - return IteratorRange(inst_iterator(&debugs_, debugs_.begin()), - inst_iterator(&debugs_, debugs_.end())); + return make_range(debugs_); } inline IteratorRange Module::debugs() const { - return IteratorRange( - const_inst_iterator(&debugs_, debugs_.cbegin()), - const_inst_iterator(&debugs_, debugs_.cend())); + return make_const_range(debugs_); } inline IteratorRange Module::annotations() { - return IteratorRange( - inst_iterator(&annotations_, annotations_.begin()), - inst_iterator(&annotations_, annotations_.end())); + return make_range(annotations_); } inline IteratorRange Module::annotations() const { - return IteratorRange( - const_inst_iterator(&annotations_, annotations_.cbegin()), - const_inst_iterator(&annotations_, annotations_.cend())); + return make_const_range(annotations_); } inline Module::const_iterator Module::cbegin() const {