0
成功と!= 0
エラーを示すために戻るCスタイルの関数がいくつかあります。それらを、値を返す代わりに関数
に「ラップ」したいと思います。void
throw
私はこのヘルパーを書きました:
void checkStatus(int status) {
if (status != 0)
// throw an error object
}
次に、確定関数をラップするためint tilt(float degrees)
に、次を使用しますboost::bind
。
function<void(float)> ntilt = bind(checkStatus, bind(tilt, _1));
ntilt(30); // this will call checkStatus(tilt(30))
そしてそれは素晴らしい働きをします。しかし、専用のラッパー関数が欲しいので、次のことができます。
function<void(float)> ntilt = wrap(tilt);
ntilt(30); // this will call checkStatus(tilt(30))
を返すすべての関数/シグニチャで機能するはずint
です。
Boostを使用してそれを行うための最良の方法は何でしょうか?