Skip to content

Commit

Permalink
adding clear, empty, at functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmanuel Nyarko authored and Emmanuel Nyarko committed May 25, 2024
1 parent b14fee7 commit 7034a0f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
8 changes: 8 additions & 0 deletions extras/AssociativeContainers/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@ class Map
size_t size() { return this->map.size(); }

V& operator[] (K const& key) { return this->map[key]; }

V& at(K const& key) { return this->map.at(key); }

bool empty() const noexcept { return this->map.empty(); }

size_t max_size() const { return this->map.max_size(); }

void clear() noexcept { this->map.clear(); }
};
13 changes: 13 additions & 0 deletions source/stdcpp/map.d
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,17 @@ module stdcpp.map;
{
return this.opIndex(key); // handle rvalue-ref
}

ref Value at( ref const Key key);

ref Value at(const Key key)
{
return this.at(key);
}

bool empty() const nothrow;

size_t max_size() const;

void clear() nothrow;
}
5 changes: 5 additions & 0 deletions source/stdcpp/test/map.d
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ unittest
mymap.opIndex(2) = 'b';
mymap.opIndex(3) = 'c';
assert(mymap.size == 3);
assert(mymap.empty == 0);
assert(mymap.at(2) == 'b');
mymap.clear();
assert(mymap.size == 0);
assert(mymap.empty == 1);
}

0 comments on commit 7034a0f

Please sign in to comment.