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

Store process' name in Process #2534

Merged
merged 7 commits into from Jun 25, 2019

[BL] Add getIfOrError() for containers.

This is a variation of getOrError() for containers using a predicate.
  • Loading branch information...
endJunction committed Jun 21, 2019
commit 606ea994d5e5881ac580ab3c09926a246f0429e8
@@ -171,6 +171,24 @@ typename Map::mapped_type const& getOrError(Map const& map, Key const& key,
return it->second;
}

//! Returns the value of from the given \c container if such an entry fulfilling
//! the \c predicate exists;
//! otherwise an \c error_message is printed and the program is aborted.
template <typename Container, typename Predicate>
typename Container::value_type const& getIfOrError(
Container const& container,
Predicate&& predicate,
std::string const& error_message)
{
auto it = std::find_if(begin(container), end(container), predicate);
if (it == end(container))
{
OGS_FATAL("Could not find element matching the predicate: %s",
error_message.c_str());
}
return *it;
}

/// Make the entries of the std::vector \c v unique. The remaining entries will
/// be sorted.
template <typename T>
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.