I have some C-style functions that return 0
to indicate success, and != 0
on error.
I'd like to "wrap" them into void
functions that throw
instead of returning a value.
I have written this helper:
void checkStatus(int status) {
if (status != 0)
// throw an error object
}
Then, to wrap a determinate function int tilt(float degrees)
, I use boost::bind
:
function<void(float)> ntilt = bind(checkStatus, bind(tilt, _1));
ntilt(30); // this will call checkStatus(tilt(30))
And it works great. But I'd like to have a dedicate wrapper function, so I can just do:
function<void(float)> ntilt = wrap(tilt);
ntilt(30); // this will call checkStatus(tilt(30))
It should work for any function/signature that returns an int
.
What would be the best way to do it using Boost?