mirror of
https://github.com/red0124/ssp.git
synced 2025-12-14 05:49:55 +01:00
make on_error accept lambda without arguments, update tests
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user