Реализация рестартов из Common Lisp в C++
https://github.com/BerserkerTroll/restart-pp
Пример использования:
#include "restartable.h"
#include <iostream>
#include <cmath>
using namespace std;
struct bad_my_sqrt_parameter { double param; }; // condition
struct my_sqrt_use_value { double val; }; // restart
struct my_sqrt_recalculate { double val; }; // restart
double my_sqrt(double d)
{
if (d < 0)
restartable {
signal_condition bad_my_sqrt_parameter{ d };
} restart_case (my_sqrt_use_value& v) {
return v.val;
} restart_case (my_sqrt_recalculate& v) {
return my_sqrt(v.val);
};
return sqrt(d);
}
int main()
{
with_handlers {
cout << my_sqrt(+4) << endl;
cout << my_sqrt(-4) << endl;
} handler_bind (bad_my_sqrt_parameter&) {
invoke_restart my_sqrt_use_value{ -1 };
};
with_handlers {
cout << my_sqrt(+4) << endl;
cout << my_sqrt(-4) << endl;
} handler_bind (bad_my_sqrt_parameter& p) {
invoke_restart my_sqrt_recalculate { -p.param };
};
}