mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2024-11-26 21:30:07 +00:00
Add make_range() & make_const_range() for creating iterator ranges.
This commit is contained in:
parent
4b3247feba
commit
95dc16d1ec
@ -105,6 +105,24 @@ class IteratorRange {
|
||||
IteratorType end_;
|
||||
};
|
||||
|
||||
// Returns a (begin, end) iterator pair for the given container.
|
||||
template <typename ValueType,
|
||||
class IteratorType = UptrVectorIterator<ValueType>>
|
||||
inline IteratorRange<IteratorType> make_range(
|
||||
std::vector<std::unique_ptr<ValueType>>& container) {
|
||||
return {IteratorType(&container, container.begin()),
|
||||
IteratorType(&container, container.end())};
|
||||
}
|
||||
|
||||
// Returns a const (begin, end) iterator pair for the given container.
|
||||
template <typename ValueType,
|
||||
class IteratorType = UptrVectorIterator<ValueType, true>>
|
||||
inline IteratorRange<IteratorType> make_const_range(
|
||||
const std::vector<std::unique_ptr<ValueType>>& container) {
|
||||
return {IteratorType(&container, container.cbegin()),
|
||||
IteratorType(&container, container.cend())};
|
||||
}
|
||||
|
||||
template <typename VT, bool IC>
|
||||
inline UptrVectorIterator<VT, IC>& UptrVectorIterator<VT, IC>::operator++() {
|
||||
++iterator_;
|
||||
|
@ -198,26 +198,19 @@ inline Module::inst_iterator Module::debug_end() {
|
||||
}
|
||||
|
||||
inline IteratorRange<Module::inst_iterator> Module::debugs() {
|
||||
return IteratorRange<inst_iterator>(inst_iterator(&debugs_, debugs_.begin()),
|
||||
inst_iterator(&debugs_, debugs_.end()));
|
||||
return make_range(debugs_);
|
||||
}
|
||||
|
||||
inline IteratorRange<Module::const_inst_iterator> Module::debugs() const {
|
||||
return IteratorRange<const_inst_iterator>(
|
||||
const_inst_iterator(&debugs_, debugs_.cbegin()),
|
||||
const_inst_iterator(&debugs_, debugs_.cend()));
|
||||
return make_const_range(debugs_);
|
||||
}
|
||||
|
||||
inline IteratorRange<Module::inst_iterator> Module::annotations() {
|
||||
return IteratorRange<inst_iterator>(
|
||||
inst_iterator(&annotations_, annotations_.begin()),
|
||||
inst_iterator(&annotations_, annotations_.end()));
|
||||
return make_range(annotations_);
|
||||
}
|
||||
|
||||
inline IteratorRange<Module::const_inst_iterator> Module::annotations() const {
|
||||
return IteratorRange<const_inst_iterator>(
|
||||
const_inst_iterator(&annotations_, annotations_.cbegin()),
|
||||
const_inst_iterator(&annotations_, annotations_.cend()));
|
||||
return make_const_range(annotations_);
|
||||
}
|
||||
|
||||
inline Module::const_iterator Module::cbegin() const {
|
||||
|
Loading…
Reference in New Issue
Block a user