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_;
|
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>
|
template <typename VT, bool IC>
|
||||||
inline UptrVectorIterator<VT, IC>& UptrVectorIterator<VT, IC>::operator++() {
|
inline UptrVectorIterator<VT, IC>& UptrVectorIterator<VT, IC>::operator++() {
|
||||||
++iterator_;
|
++iterator_;
|
||||||
|
@ -198,26 +198,19 @@ inline Module::inst_iterator Module::debug_end() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline IteratorRange<Module::inst_iterator> Module::debugs() {
|
inline IteratorRange<Module::inst_iterator> Module::debugs() {
|
||||||
return IteratorRange<inst_iterator>(inst_iterator(&debugs_, debugs_.begin()),
|
return make_range(debugs_);
|
||||||
inst_iterator(&debugs_, debugs_.end()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline IteratorRange<Module::const_inst_iterator> Module::debugs() const {
|
inline IteratorRange<Module::const_inst_iterator> Module::debugs() const {
|
||||||
return IteratorRange<const_inst_iterator>(
|
return make_const_range(debugs_);
|
||||||
const_inst_iterator(&debugs_, debugs_.cbegin()),
|
|
||||||
const_inst_iterator(&debugs_, debugs_.cend()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline IteratorRange<Module::inst_iterator> Module::annotations() {
|
inline IteratorRange<Module::inst_iterator> Module::annotations() {
|
||||||
return IteratorRange<inst_iterator>(
|
return make_range(annotations_);
|
||||||
inst_iterator(&annotations_, annotations_.begin()),
|
|
||||||
inst_iterator(&annotations_, annotations_.end()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline IteratorRange<Module::const_inst_iterator> Module::annotations() const {
|
inline IteratorRange<Module::const_inst_iterator> Module::annotations() const {
|
||||||
return IteratorRange<const_inst_iterator>(
|
return make_const_range(annotations_);
|
||||||
const_inst_iterator(&annotations_, annotations_.cbegin()),
|
|
||||||
const_inst_iterator(&annotations_, annotations_.cend()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Module::const_iterator Module::cbegin() const {
|
inline Module::const_iterator Module::cbegin() const {
|
||||||
|
Loading…
Reference in New Issue
Block a user