Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure container sizes are runtime integers. #919

Merged
merged 1 commit into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions hilti/runtime/include/types/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ class Map : protected std::map<K, V> {

using key_type = typename M::key_type;
using value_type = typename M::value_type;
using size_type = uint64_t;

using iterator = typename map::Iterator<K, V>;
using const_iterator = typename map::ConstIterator<K, V>;
Expand Down Expand Up @@ -257,13 +258,12 @@ class Map : protected std::map<K, V> {
auto end() const { return this->cend(); }

auto begin() { return iterator(static_cast<M&>(*this).begin(), _control); }

auto end() { return iterator(static_cast<M&>(*this).end(), _control); }

auto cbegin() const { return const_iterator(static_cast<const M&>(*this).begin(), _control); }

auto cend() const { return const_iterator(static_cast<const M&>(*this).end(), _control); }

size_type size() const { return M::size(); }

/** Erases all elements from the map.
*
Expand Down Expand Up @@ -292,9 +292,6 @@ class Map : protected std::map<K, V> {
return removed;
}

// Methods of `std::map`.
using M::size;

friend bool operator==(const Map& a, const Map& b) { return static_cast<const M&>(a) == static_cast<const M&>(b); }
friend bool operator!=(const Map& a, const Map& b) { return ! (a == b); }

Expand Down
6 changes: 3 additions & 3 deletions hilti/runtime/include/types/set.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class Set : protected std::set<T> {
using key_type = T;
using value_type = T;

using size_type = typename V::size_type;
using size_type = uint64_t;

Set() = default;
Set(const Set&) = default;
Expand All @@ -140,9 +140,10 @@ class Set : protected std::set<T> {
bool contains(const T& t) const { return this->count(t); }

auto begin() const { return iterator(static_cast<const V&>(*this).begin(), empty() ? nullptr : _control); }

auto end() const { return iterator(static_cast<const V&>(*this).end(), empty() ? nullptr : _control); }

size_type size() const { return V::size(); }

/** Removes an element from the set.
*
* This function invalidates all iterators into the set.
Expand Down Expand Up @@ -171,7 +172,6 @@ class Set : protected std::set<T> {
// Methods of `std::set`. These methods *must not* cause any iterator invalidation.
using V::empty;
using V::insert;
using V::size;

friend bool operator==(const Set& a, const Set& b) { return static_cast<const V&>(a) == static_cast<const V&>(b); }
friend bool operator!=(const Set& a, const Set& b) { return ! (a == b); }
Expand Down
5 changes: 3 additions & 2 deletions hilti/runtime/include/types/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class Vector : protected std::vector<T, Allocator> {

using V = std::vector<T, Allocator>;

using size_type = typename V::size_type;
using size_type = uint64_t;
using reference = T&;
using const_reference = const T&;
using iterator = vector::Iterator<T, Allocator>;
Expand Down Expand Up @@ -465,6 +465,8 @@ class Vector : protected std::vector<T, Allocator> {
auto cbegin() const { return const_iterator(0u, _control); }
auto cend() const { return const_iterator(size(), _control); }

size_t size() const { return V::size(); }

// Methods of `std::vector`.
using typename V::value_type;
using V::at;
Expand All @@ -475,7 +477,6 @@ class Vector : protected std::vector<T, Allocator> {
using V::push_back;
using V::reserve;
using V::resize;
using V::size;

friend bool operator==(const Vector& a, const Vector& b) {
return static_cast<const V&>(a) == static_cast<const V&>(b);
Expand Down