Skip to content

Commit

Permalink
Add static asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
Dobiasd committed Apr 15, 2024
1 parent 61c29a3 commit d5e238f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/fplus/numeric.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,8 @@ std::function<X(X)> divide_by(const X& x)
// div_pos_int_ceil(5, 3) == 2
template<typename X>
static auto div_pos_int_ceil(X numerator, X denominator) {
static_assert(std::is_integral<X>::value, "type must be integral");
static_assert(!std::is_signed<X>::value, "type must be unsigned");
return numerator / denominator + (numerator % denominator != 0);
}

Expand Down
4 changes: 3 additions & 1 deletion include_all_in_one/include/fplus/fplus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8352,10 +8352,12 @@ std::function<X(X)> divide_by(const X& x)
}

// API search type: div_pos_int_ceil : (a, a) -> a
// Integer division, but rounding up instead of down.
// Positive integer division, but rounding up instead of down.
// div_pos_int_ceil(5, 3) == 2
template<typename X>
static auto div_pos_int_ceil(X numerator, X denominator) {
static_assert(std::is_integral<X>::value, "type must be integral");
static_assert(!std::is_signed<X>::value, "type must be unsigned");
return numerator / denominator + (numerator % denominator != 0);
}

Expand Down

0 comments on commit d5e238f

Please sign in to comment.