Some const correctness fixes

This commit is contained in:
karl 2021-03-15 14:14:21 +01:00
parent 560abcb201
commit 49b158dafe

View File

@ -53,7 +53,7 @@ class Vector {
// Equals Operator: Returns true if the number of elements is identical and // Equals Operator: Returns true if the number of elements is identical and
// each of these elements are equal // each of these elements are equal
bool operator==(const Vector &other) { bool operator==(const Vector &other) const {
if (size() != other.size()) return false; if (size() != other.size()) return false;
for (unsigned int i = 0; i < size(); i++) { for (unsigned int i = 0; i < size(); i++) {
@ -105,7 +105,7 @@ class Vector {
} }
} }
T *as_array() { T *as_array() const {
return data; return data;
} }
@ -172,19 +172,19 @@ class Vector {
// Return a sensible capacity for the given size (including some // Return a sensible capacity for the given size (including some
// padding). // padding).
unsigned int get_capacity_for_size(unsigned int size) { unsigned int get_capacity_for_size(unsigned int size) const {
return size * 2 + 5; return size * 2 + 5;
} }
// Return true if the Vector is holding much more memory (capacity) than it // Return true if the Vector is holding much more memory (capacity) than it
// currently needs (element_count). // currently needs (element_count).
inline bool is_using_excessive_memory() { inline bool is_using_excessive_memory() const {
return 10 + element_count * 2 < capacity; return 10 + element_count * 2 < capacity;
} }
// Return true if the passed new_size would cause the Vector to exceed the // Return true if the passed new_size would cause the Vector to exceed the
// current capacity (meaning it must be expanded with `reallocate` first). // current capacity (meaning it must be expanded with `reallocate` first).
inline bool new_size_exceeds_capacity(unsigned int new_size) { inline bool new_size_exceeds_capacity(unsigned int new_size) const {
return new_size > capacity; return new_size > capacity;
} }