We keep using vectors that map from some Id sub-type to something else, and we keep having to deal with some null-index.
This is a wrapper class that uses templates and allows for static type checking of the id type.
I am using a weird convention for the accessor function:
operator[] for mutable access where one want to wired something like myMap[idx] = 5.
at(idx) for const access where one only want to read the value
This is a bit weird and can be improved.
For bool specialization, we have to worry about the fact that std::vector is not an STL container, and we cannot using operator[] for mutating values.
Instead we then use the following interface:
get(idx) for reading a value
set(idx, value) for setting the value.
I personally dislike have get and set functions, and we can get the same interface as above if we just dig a bit deeper into the c++ library.... (the operator[] would have to return a __bit_reference)
We keep using vectors that map from some Id sub-type to something else, and we keep having to deal with some null-index.
This is a wrapper class that uses templates and allows for static type checking of the id type.
I am using a weird convention for the accessor function:
operator[]
for mutable access where one want to wired something likemyMap[idx] = 5
.at(idx)
for const access where one only want to read the value This is a bit weird and can be improved.For bool specialization, we have to worry about the fact that std::vector is not an STL container, and we cannot using
operator[]
for mutating values. Instead we then use the following interface:get(idx)
for reading a valueset(idx, value)
for setting the value. I personally dislike have get and set functions, and we can get the same interface as above if we just dig a bit deeper into the c++ library.... (the operator[] would have to return a__bit_reference
)