Skip to content

Commit

Permalink
use constexpr
Browse files Browse the repository at this point in the history
  • Loading branch information
madsbk committed Sep 29, 2024
1 parent a28d806 commit 439f59f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cpp/include/kvikio/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ inline constexpr std::size_t page_size = 4096;
template <typename T, std::enable_if_t<std::is_integral_v<T>>* = nullptr>
[[nodiscard]] std::int64_t convert_to_64bit(T value)
{
if (value >= std::numeric_limits<std::int64_t>::max()) {
throw std::overflow_error("convert_to_64bit(x): x too large to fit std::int64_t");
if constexpr (std::numeric_limits<T>::max() > std::numeric_limits<std::int64_t>::max()) {
if (value > std::numeric_limits<std::int64_t>::max()) {
throw std::overflow_error("convert_to_64bit(x): x too large to fit std::int64_t");
}
}
return std::int64_t(value);
}
Expand Down

0 comments on commit 439f59f

Please sign in to comment.