Skip to content

Commit

Permalink
chore: add contains utility function
Browse files Browse the repository at this point in the history
  • Loading branch information
TendTo committed Jul 19, 2024
1 parent 6955c96 commit 5a2024a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ const Environment::mapped_type &Environment::at(const Environment::key_type &key
return value;
}

bool Environment::contains(const key_type &key) const {
return map_.find(key) != map_.end();
}

Environment::mapped_type &Environment::operator[](const key_type &key) {
if (key.is_dummy()) {
ostringstream oss;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ class Environment {
* (throwing a runtime error instead) if the key does not exist. */
const mapped_type &operator[](const key_type &key) const;

/** Checks whether the environment contains a variable @p key. */
bool contains(const key_type &key) const;

friend std::ostream &operator<<(std::ostream &os, const Environment &env);

private:
Expand Down

0 comments on commit 5a2024a

Please sign in to comment.