Skip to content

Commit

Permalink
multiprecision: big_uint: fix constructors from string-like types
Browse files Browse the repository at this point in the history
  • Loading branch information
ioxid committed Dec 14, 2024
1 parent 1972979 commit 1ebae56
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <iostream>
#include <stdexcept>
#include <string>
#include <string_view>
#include <system_error>
#include <type_traits>

Expand Down Expand Up @@ -156,7 +155,7 @@ namespace nil::crypto3::multiprecision {

constexpr big_uint() noexcept {}

template<typename T, std::enable_if_t<std::is_convertible_v<T, std::string_view>, int> = 0>
template<typename T, std::enable_if_t<detail::is_supported_string_type_v<T>, int> = 0>
constexpr big_uint(const T& str) {
*this = str;
}
Expand Down Expand Up @@ -188,7 +187,7 @@ namespace nil::crypto3::multiprecision {

// Assignment

template<typename T, std::enable_if_t<std::is_convertible_v<T, std::string_view>, int> = 0>
template<typename T, std::enable_if_t<detail::is_supported_string_type_v<T>, int> = 0>
constexpr big_uint& operator=(const T& str) {
*this = detail::parse_int<Bits>(str);
return *this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <algorithm>
#include <climits>
#include <cstddef>
#include <string>
#include <string_view>
#include <type_traits>

#include "nil/crypto3/multiprecision/detail/big_uint/storage.hpp"
Expand All @@ -21,6 +23,14 @@ namespace nil::crypto3::multiprecision {
template<typename T>
constexpr bool is_integral_v = std::is_integral_v<T> || is_big_uint_v<T>;

template<typename T>
constexpr bool is_supported_string_type_v =
(std::is_array_v<T> &&
std::is_same_v<std::remove_cv_t<std::remove_extent_t<T>>, char>) ||
(std::is_pointer_v<T> &&
(std::is_same_v<std::remove_cv_t<std::remove_pointer_t<T>>, char>)) ||
std::is_same_v<T, std::string_view> || std::is_same_v<T, std::string>;

template<typename T, std::enable_if_t<std::is_integral_v<T>, int> = 0>
constexpr std::size_t get_bits() {
return sizeof(T) * CHAR_BIT;
Expand Down

0 comments on commit 1ebae56

Please sign in to comment.