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 25, 2024
1 parent 7034a0f commit b9cef4a
Show file tree
Hide file tree
Showing 3 changed files with 12 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)
{
return this.count(key);
}
}
1 change: 1 addition & 0 deletions source/stdcpp/test/map.d
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ unittest
mymap.clear();
assert(mymap.size == 0);
assert(mymap.empty == 1);
assert(mymap.count(1) == 1); // key 1 exists once
}

0 comments on commit b9cef4a

Please sign in to comment.