diff --git a/ciphers/uint128_t.hpp b/ciphers/uint128_t.hpp index b30ef2429..2af5f9d75 100644 --- a/ciphers/uint128_t.hpp +++ b/ciphers/uint128_t.hpp @@ -85,56 +85,14 @@ class uint128_t { public: uint128_t() = default; + /** + * @brief Parameterized constructor + * @tparam T integral type + * @param low lower part 8-bit unisgned integer + */ template ::value, T>::type> explicit uint128_t(T low) : s(low), f(0) {} - /** - * @brief Parameterized constructor - * @param low lower part 8-bit unisgned integer - */ - explicit uint128_t(uint8_t low) : s(low), f(0) {} - - /** - * @brief Parameterized constructor - * @param low lower part 16-bit unisgned integer - */ - explicit uint128_t(uint16_t low) : s(low), f(0) {} - - /** - * @brief Parameterized constructor - * @param low lower part 32-bit unisgned integer - */ - explicit uint128_t(uint32_t low) : s(low), f(0) {} - - /** - * @brief Parameterized constructor - * @param low lower part 64-bit unisgned integer - */ - explicit uint128_t(uint64_t low) : s(low), f(0) {} - - /** - * @brief Parameterized constructor - * @param low lower part 8-bit integer - */ - explicit uint128_t(int8_t low) : s(low), f(0) {} - - /** - * @brief Parameterized constructor - * @param low lower part 16-bit integer - */ - explicit uint128_t(int16_t low) : s(low), f(0) {} - - /** - * @brief Parameterized constructor - * @param low lower part 32-bit integer - */ - explicit uint128_t(int32_t low) : s(low), f(0) {} - - /** - * @brief Parameterized constructor - * @param low lower part 64-bit integer - */ - explicit uint128_t(int64_t low) : s(low), f(0) {} /** * @brief Parameterized constructor @@ -190,13 +148,11 @@ class uint128_t { // Casting operators inline operator bool() const { return f || s; } - inline operator uint8_t() const { return s & 0xFF; } - - inline operator uint16_t() const { return s & 0xFFFF; } - - inline operator uint32_t() const { return s & 0xFFFFFFFF; } - - inline operator uint64_t() const { return s; } + template ::value, T>::type> + inline operator T() const { + return static_cast(s); + } /** * @brief returns lower 64-bit integer part diff --git a/ciphers/uint256_t.hpp b/ciphers/uint256_t.hpp index 6e81af8bd..72dea6dff 100644 --- a/ciphers/uint256_t.hpp +++ b/ciphers/uint256_t.hpp @@ -69,60 +69,6 @@ class uint256_t { std::is_integral::value, T>::type> explicit uint256_t(T low) : s(low), f(0) {} - /** - * @brief Parameterized constructor - * @param low lower part 8-bit unisgned integer - */ - explicit uint256_t(uint8_t low) : s(low), f(0) {} - - /** - * @brief Parameterized constructor - * @param low lower part 16-bit unisgned integer - */ - explicit uint256_t(uint16_t low) : s(low), f(0) {} - - /** - * @brief Parameterized constructor - * @param low lower part 32-bit unisgned integer - */ - explicit uint256_t(uint32_t low) : s(low), f(0) {} - - /** - * @brief Parameterized constructor - * @param low lower part 64-bit unisgned integer - */ - explicit uint256_t(uint64_t low) : s(low), f(0) {} - - /** - * @brief Parameterized constructor - * @param low lower part 128-bit unisgned integer - */ - explicit uint256_t(const uint128_t &low) : s(low), f(0) {} - - /** - * @brief Parameterized constructor - * @param low lower part 8-bit integer - */ - explicit uint256_t(int8_t low) : s(low), f(0) {} - - /** - * @brief Parameterized constructor - * @param low lower part 16-bit integer - */ - explicit uint256_t(int16_t low) : s(low), f(0) {} - - /** - * @brief Parameterized constructor - * @param low lower part 32-bit integer - */ - explicit uint256_t(int32_t low) : s(low), f(0) {} - - /** - * @brief Parameterized constructor - * @param low lower part 64-bit integer - */ - explicit uint256_t(int64_t low) : s(low), f(0) {} - /** * @brief Parameterized constructor * @param str Integer string (hexadecimal starting with 0x.. or decimal) @@ -183,13 +129,14 @@ class uint256_t { inline operator bool() const { return f || s; } - inline operator uint8_t() const { return s.lower(); } - - inline operator uint16_t() const { return s.lower(); } - - inline operator uint32_t() const { return s.lower(); } - - inline operator uint64_t() const { return s.lower(); } + /** + * @brief casting operator + */ + template ::value, T>::type> + inline operator T() const { + return static_cast(s); + } inline operator uint128_t() const { return s; }