| |
| |
|
|
| #pragma once |
|
|
| #include <type_traits> |
|
|
| namespace onnxruntime { |
| |
| |
| |
| |
| |
| |
| template <typename Container> |
| class ConstPointerContainer { |
| public: |
| using T = typename std::remove_pointer<typename Container::value_type>::type; |
|
|
| class ConstIterator { |
| public: |
| using const_iterator = typename Container::const_iterator; |
| using iterator_category = std::input_iterator_tag; |
| using value_type = T*; |
| using difference_type = std::ptrdiff_t; |
| using pointer = T**; |
| using reference = T*&; |
|
|
| |
| explicit ConstIterator(const_iterator position) noexcept : current_{position}, item_{nullptr} {} |
| ConstIterator(const ConstIterator& other) = default; |
| ConstIterator& operator=(const ConstIterator& other) = default; |
|
|
| bool operator==(const ConstIterator& other) const noexcept { return current_ == other.current_; } |
| bool operator!=(const ConstIterator& other) const noexcept { return current_ != other.current_; } |
|
|
| ConstIterator& operator++() { |
| ++current_; |
| return *this; |
| } |
|
|
| ConstIterator operator++(int) { |
| ConstIterator tmp{*this}; |
| ++(*this); |
| return tmp; |
| } |
|
|
| const T*& operator*() const { |
| item_ = *current_; |
| return item_; |
| } |
|
|
| const T** operator->() const { return &(operator*()); }; |
|
|
| private: |
| const_iterator current_; |
| mutable const T* item_; |
| }; |
|
|
| |
| |
| |
| |
| explicit ConstPointerContainer(const Container& data) noexcept : data_(data) {} |
|
|
| size_t size() const noexcept { return data_.size(); } |
| bool empty() const noexcept { return data_.empty(); } |
|
|
| ConstIterator cbegin() const noexcept { return ConstIterator(data_.cbegin()); } |
| ConstIterator cend() const noexcept { return ConstIterator(data_.cend()); } |
|
|
| ConstIterator begin() const noexcept { return ConstIterator(data_.cbegin()); } |
| ConstIterator end() const noexcept { return ConstIterator(data_.cend()); } |
|
|
| const T* operator[](size_t index) const { return data_[index]; } |
|
|
| const T* at(size_t index) const { |
| ORT_ENFORCE(index < data_.size()); |
| return data_[index]; |
| } |
|
|
| private: |
| const Container& data_; |
| }; |
| } |
|
|