#ifndef UTIL_SATURATE_CAST_H_
#define UTIL_SATURATE_CAST_H_
#include <cmath>
#include <limits>
#include <type_traits>
namespace openscreen {
template <typename To, typename From>
constexpr std::enable_if_t<
std::is_same<std::remove_cv<To>, std::remove_cv<From>>::value,
To>
saturate_cast(From from) { … }
template <typename To, typename From>
constexpr std::enable_if_t<
std::is_integral<From>::value && std::is_integral<To>::value &&
(std::is_signed<From>::value == std::is_signed<To>::value),
To>
saturate_cast(From from) { … }
template <typename To, typename From>
constexpr std::enable_if_t<
std::is_integral<From>::value && std::is_integral<To>::value &&
std::is_signed<From>::value && !std::is_signed<To>::value,
To>
saturate_cast(From from) { … }
template <typename To, typename From>
constexpr std::enable_if_t<
std::is_integral<From>::value && std::is_integral<To>::value &&
!std::is_signed<From>::value && std::is_signed<To>::value,
To>
saturate_cast(From from) { … }
template <typename To, typename From>
constexpr std::enable_if_t<std::is_floating_point<From>::value &&
std::is_integral<To>::value,
To>
saturate_cast(From from) { … }
template <typename To, typename From>
constexpr std::enable_if_t<std::is_floating_point<From>::value &&
std::is_integral<To>::value,
To>
rounded_saturate_cast(From from) { … }
}
#endif