Skip to content

Commit

Permalink
count function
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmanuel Nyarko authored and Emmanuel Nyarko committed May 26, 2024
1 parent 7034a0f commit 4667da0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions extras/AssociativeContainers/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ class Map
size_t max_size() const { return this->map.max_size(); }

void clear() noexcept { this->map.clear(); }

size_t count(K const& key ) const { return this->map.count(key); }

};
9 changes: 8 additions & 1 deletion source/stdcpp/map.d
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module stdcpp.map;

ref Value at( ref const Key key);

ref Value at(const Key key)
extern(D) ref Value at(const Key key)
{
return this.at(key);
}
Expand All @@ -43,4 +43,11 @@ module stdcpp.map;
size_t max_size() const;

void clear() nothrow;

size_t count(ref const Key key) const;

extern(D) size_t count(const Key key) const
{
return this.count(key);
}
}
2 changes: 2 additions & 0 deletions source/stdcpp/test/map.d
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ unittest
assert(mymap.size == 3);
assert(mymap.empty == 0);
assert(mymap.at(2) == 'b');
assert(mymap.count(1) == 1);
mymap.clear();
assert(mymap.size == 0);
assert(mymap.empty == 1);
assert(mymap.count(1) == 0); // container cleared
}

0 comments on commit 4667da0

Please sign in to comment.