#ifndef MIRRORSEARCH_UPTR_H #define MIRRORSEARCH_UPTR_H #include #include namespace MirrorSearch { typedef std::function OnError; std::string failingFunction(void * const func); void defaultErrorHandler(const std::string &); template using UPtr = std::unique_ptr; template R * make_unique(R * (*func)(P...), OnError onError, A ... p) { if (auto obj = func(p...)) { return obj; } onError(failingFunction((void * const)func)); throw std::runtime_error("Error handler did not throw"); } template UPtr make_unique(R*(*get)(P...), void(*release)(R*), OnError onError, A ... p) { return std::unique_ptr(make_unique(get, onError, p...), release); } } #endif