#ifndef SVK_HELPER_FUNCTIONS
#define SVK_HELPER_FUNCTIONS

#include <stdexcept>
#include <string>

inline void throwIfNullptr(void const* ptr, std::string const& message)
{
    if (ptr == nullptr)
        throw std::runtime_error(message);
}

// std::clamp doesn't allow T to be a different type than min and max.
template <typename T, typename D>
T clamp(T const& value, D const& min, D const& max)
{
	if (min > max)
		throw std::invalid_argument("clamp() can't be called with min > max");
	if (value < min)
		return static_cast<T>(min);
	else if (value > max)
		return static_cast<T>(max);
    return value;
}

#endif // SVK_HELPER_FUNCTIONS