diff --git a/src/enforce.hpp b/src/enforce.hpp index 48d50462..f2016efe 100644 --- a/src/enforce.hpp +++ b/src/enforce.hpp @@ -28,58 +28,21 @@ namespace Exiv2::Internal { * type exception_t * * @tparam exception_t Exception type that is thrown, must provide a - * constructor that accepts a single argument to which arg1 is forwarded. - * - * @todo once we have C++>=11 use variadic templates and std::forward to remove - * all overloads of enforce - */ -template -inline void enforce(bool condition, const T& arg1) { - if (!condition) { - throw exception_t(arg1); - } -} - -/*! - * @brief Ensure that condition is true, otherwise throw an Exiv2::Error with - * the given error_code. - */ -inline void enforce(bool condition, Exiv2::ErrorCode err_code) { - if (!condition) { - throw Exiv2::Error(err_code); - } -} - -/*! - * @brief Ensure that condition is true, otherwise throw an Exiv2::Error with - * the given error_code & arg1. - */ -template -inline void enforce(bool condition, Exiv2::ErrorCode err_code, const T& arg1) { - if (!condition) { - throw Exiv2::Error(err_code, arg1); - } -} - -/*! - * @brief Ensure that condition is true, otherwise throw an Exiv2::Error with - * the given error_code, arg1 & arg2. + * constructor that accepts a single argument to which args are forwarded. */ -template -inline void enforce(bool condition, Exiv2::ErrorCode err_code, const T& arg1, const U& arg2) { +template +constexpr void enforce(bool condition, T&&... args) { if (!condition) { - throw Exiv2::Error(err_code, arg1, arg2); + throw exception_t(std::forward(args)...); } } /*! * @brief Ensure that condition is true, otherwise throw an Exiv2::Error with - * the given error_code, arg1, arg2 & arg3. + * the given error_code & arguments. */ -template -inline void enforce(bool condition, Exiv2::ErrorCode err_code, const T& arg1, const U& arg2, const V& arg3) { - if (!condition) { - throw Exiv2::Error(err_code, arg1, arg2, arg3); - } +template +constexpr void enforce(bool condition, Exiv2::ErrorCode err_code, T&&... args) { + enforce(condition, err_code, std::forward(args)...); } } // namespace Exiv2::Internal