diff options
author | Kushal Pal <kushalpal109@gmail.com> | 2024-08-19 09:28:25 +0000 |
---|---|---|
committer | P-E-P <32375388+P-E-P@users.noreply.github.com> | 2024-09-09 08:33:02 +0000 |
commit | fe780d77dbd7c16076817a43b5f72ce645b2bb48 (patch) | |
tree | 50afe5f84ba865ae2bc8f1db210e482f5bf06331 /gcc | |
parent | 4050bf70e245e0bedcfa5198e7a1e6bd14db6b0f (diff) | |
download | gcc-fe780d77dbd7c16076817a43b5f72ce645b2bb48.zip gcc-fe780d77dbd7c16076817a43b5f72ce645b2bb48.tar.gz gcc-fe780d77dbd7c16076817a43b5f72ce645b2bb48.tar.bz2 |
Introduce `IndexVec`
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-place.h (struct Loan):
Introduce new class `IndexVec` inspired from IndexVec of rust.
It acts as a wrapper around `std::vector` and lets user specify
a strong type to use as index.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/checks/errors/borrowck/rust-bir-place.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-place.h b/gcc/rust/checks/errors/borrowck/rust-bir-place.h index 728728c..6a6519d 100644 --- a/gcc/rust/checks/errors/borrowck/rust-bir-place.h +++ b/gcc/rust/checks/errors/borrowck/rust-bir-place.h @@ -199,6 +199,25 @@ struct Loan location_t location; }; +// I is the index type, T is the contained type +template <typename I, typename T> class IndexVec +{ + std::vector<T> internal_vector; + +public: + T &at (I pid) { return internal_vector[pid.value]; } + const T &at (I pid) const { return internal_vector[pid.value]; } + T &operator[] (I pid) { return internal_vector[pid.value]; } + const T &operator[] (I pid) const { return internal_vector[pid.value]; } + + void push_back (T &¶m) { internal_vector.push_back (std::move (param)); } + template <typename... Args> void emplace_back (Args &&... args) + { + internal_vector.emplace_back (std::forward<Args> (args)...); + } + size_t size () const { return internal_vector.size (); } +}; + /** Allocated places and keeps track of paths. */ class PlaceDB { |