diff options
author | Mark D. Roth <roth@google.com> | 2018-01-23 14:57:11 -0800 |
---|---|---|
committer | Mark D. Roth <roth@google.com> | 2018-01-23 14:57:11 -0800 |
commit | 9ab4d0c82699064efebd8a15eebf66e3db8bf256 (patch) | |
tree | fd6a532ef1e1580572da8f55811b819a5f03f5f5 /src/core/lib | |
parent | 19688bf7a8b8b172faeba347d81d9b6cafecb874 (diff) |
Add const version of operator[].
Diffstat (limited to 'src/core/lib')
-rw-r--r-- | src/core/lib/gprpp/inlined_vector.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/core/lib/gprpp/inlined_vector.h b/src/core/lib/gprpp/inlined_vector.h index 55ba77debd..8044c682d1 100644 --- a/src/core/lib/gprpp/inlined_vector.h +++ b/src/core/lib/gprpp/inlined_vector.h @@ -61,6 +61,15 @@ class InlinedVector { } } + const T& operator[](size_t offset) const { + assert(offset < size_); + if (offset < N) { + return *reinterpret_cast<const T*>(inline_ + offset); + } else { + return dynamic_[offset - N]; + } + } + template <typename... Args> void emplace_back(Args&&... args) { if (size_ < N) { |