31 lines
633 B
C++
31 lines
633 B
C++
|
|
#pragma once
|
|
|
|
#ifndef MIJIN_UTIL_EXCEPTION_HPP_INCLUDED
|
|
#define MIJIN_UTIL_EXCEPTION_HPP_INCLUDED 1
|
|
|
|
#include <stdexcept>
|
|
|
|
namespace mijin
|
|
{
|
|
|
|
//
|
|
// public defines
|
|
//
|
|
|
|
//
|
|
// public functions
|
|
//
|
|
|
|
template<typename TCondition, typename TException = std::runtime_error, typename... TExceptionArgs>
|
|
inline decltype(auto) ensure(TCondition&& condition, TExceptionArgs&&... args)
|
|
{
|
|
if (!static_cast<bool>(std::forward<TCondition>(condition)))
|
|
{
|
|
throw TException(std::forward<TExceptionArgs>(args)...);
|
|
}
|
|
return std::forward<TCondition>(condition);
|
|
}
|
|
} // namespace mijin
|
|
#endif // MIJIN_UTIL_EXCEPTION_HPP_INCLUDED
|