Skip to content

Commit

Permalink
Fix ambiguous overloads on 32-bit platforms
Browse files Browse the repository at this point in the history
On the 32-bit platforms in CI (windows and emscripten) large_int_t and
large_uint_t seem to alias each other in function definitions. Fix this by
using signed/unsigned concepts for the parameter. That way the incorrect
function will not be considered.

This required small bug fix in snitch::concepts. signed_integral and
unsigned_integral concepts need to check for sign and also make sure the
type is integral so that floating point or other types are not considered.
  • Loading branch information
CrustyAuklet committed Apr 30, 2024
1 parent 3aed57c commit dc67a89
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
16 changes: 8 additions & 8 deletions include/snitch/snitch_append.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ SNITCH_EXPORT [[nodiscard]] bool append_fast(small_string_span ss, double f) noe
return could_fit;
}

template<large_uint_t Base = 10u>
[[nodiscard]] constexpr std::size_t num_digits(large_uint_t x) noexcept {
template<large_uint_t Base = 10u, unsigned_integral T>
[[nodiscard]] constexpr std::size_t num_digits(T x) noexcept {
return x >= Base ? 1u + num_digits<Base>(x / Base) : 1u;
}

template<large_int_t Base = 10>
[[nodiscard]] constexpr std::size_t num_digits(large_int_t x) noexcept {
template<large_int_t Base = 10, signed_integral T>
[[nodiscard]] constexpr std::size_t num_digits(T x) noexcept {
return (x >= Base || x <= -Base) ? 1u + num_digits<Base>(x / Base) : x > 0 ? 1u : 2u;
}

Expand All @@ -61,8 +61,8 @@ constexpr std::array<char, 16> digits = {'0', '1', '2', '3', '4', '5', '6', '7',
constexpr std::size_t max_uint_length = num_digits(std::numeric_limits<large_uint_t>::max());
constexpr std::size_t max_int_length = max_uint_length + 1;

template<large_uint_t Base = 10u>
[[nodiscard]] constexpr bool append_constexpr(small_string_span ss, large_uint_t i) noexcept {
template<large_uint_t Base = 10u, unsigned_integral T>
[[nodiscard]] constexpr bool append_constexpr(small_string_span ss, T i) noexcept {
if (i != 0u) {
small_string<max_uint_length> tmp;
tmp.resize(num_digits<Base>(i));
Expand All @@ -76,8 +76,8 @@ template<large_uint_t Base = 10u>
}
}

template<large_int_t Base = 10>
[[nodiscard]] constexpr bool append_constexpr(small_string_span ss, large_int_t i) noexcept {
template<large_int_t Base = 10, signed_integral T>
[[nodiscard]] constexpr bool append_constexpr(small_string_span ss, T i) noexcept {
if (i > 0) {
small_string<max_int_length> tmp;
tmp.resize(num_digits<Base>(i));
Expand Down
7 changes: 4 additions & 3 deletions include/snitch/snitch_concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
#include <type_traits>

namespace snitch {

template<typename T>
concept signed_integral = std::is_signed_v<T>;
concept integral = std::is_integral_v<T>;

template<typename T>
concept unsigned_integral = std::is_unsigned_v<T>;
concept signed_integral = integral<T> && std::is_signed_v<T>;

template<typename T>
concept integral = std::is_integral_v<T>;
concept unsigned_integral = integral<T> && std::is_unsigned_v<T>;

template<typename T>
concept floating_point = std::is_floating_point_v<T>;
Expand Down

0 comments on commit dc67a89

Please sign in to comment.