make on_error accept lambda without arguments, update tests

This commit is contained in:
ado
2020-12-26 00:42:01 +01:00
parent 371da072be
commit 16f4648cb3
2 changed files with 15 additions and 11 deletions

View File

@@ -120,9 +120,14 @@ class parser {
}
template <typename Fun>
auto on_error(Fun fun) {
auto on_error(Fun&& fun) {
if (!parser_.valid()) {
fun(parser_.error_msg());
if constexpr (std::is_invocable_v<Fun>) {
fun();
} else {
std::invoke(std::forward<Fun>(fun),
parser_.error_msg());
}
}
return *this;
}