ipaddress 1.1.0
|
Class for representing a 128-bit unsigned integer. More...
#include <uint128.hpp>
Public Types | |
enum class | format { decimal = 0 , octal , hexadecimal } |
Enumerates the string formats available for uint128_t . More... | |
Public Member Functions | |
constexpr inline | uint128_t () noexcept=default |
Default constructor. | |
constexpr inline | uint128_t (const uint128_t &other) noexcept=default |
Copy constructor. | |
constexpr inline | uint128_t (uint128_t &&other) noexcept=default |
Move constructor. | |
constexpr inline uint128_t & | operator= (const uint128_t &other) noexcept=default |
Assignment operator. | |
constexpr inline uint128_t & | operator= (uint128_t &&other) noexcept=default |
Move assignment operator. | |
constexpr inline | uint128_t (uint64_t upper, uint64_t lower) noexcept |
Constructs a uint128_t instance from upper and lower parts. | |
constexpr inline | uint128_t (unsigned long long lower) noexcept |
Constructs a uint128_t instance from an unsigned integer. | |
constexpr inline | uint128_t (unsigned long lower) noexcept |
Constructs a uint128_t instance from an unsigned integer. | |
constexpr inline | uint128_t (unsigned int lower) noexcept |
Constructs a uint128_t instance from an unsigned integer. | |
constexpr inline | uint128_t (unsigned short lower) noexcept |
Constructs a uint128_t instance from an unsigned integer. | |
constexpr inline | uint128_t (long long lower) noexcept |
Constructs a uint128_t instance from a signed integer. | |
constexpr inline | uint128_t (long lower) noexcept |
Constructs a uint128_t instance from a signed integer. | |
constexpr inline | uint128_t (int lower) noexcept |
Constructs a uint128_t instance from a signed integer. | |
constexpr inline | uint128_t (short lower) noexcept |
Constructs a uint128_t instance from a signed integer. | |
inline | uint128_t (double value) noexcept |
Constructs a uint128_t instance from a floating-point value. | |
inline | uint128_t (long double value) noexcept |
Constructs a uint128_t instance from a floating-point value. | |
inline | uint128_t (float value) noexcept |
Constructs a uint128_t instance from a floating-point value. | |
constexpr inline uint64_t | lower () const noexcept |
Retrieves the lower 64 bits of the uint128_t value. | |
constexpr inline uint64_t | upper () const noexcept |
Retrieves the upper 64 bits of the uint128_t value. | |
constexpr inline size_t | hash () const noexcept |
Computes the hash value of the uint128_t instance. | |
constexpr inline void | swap (uint128_t &other) noexcept |
Swaps the values of two uint128_t instances. | |
inline std::string | to_string (format fmt=format::decimal) const |
Converts the uint128_t value to a string representation. | |
inline std::wstring | to_wstring (format fmt=format::decimal) const |
Converts the uint128_t value to a string representation. | |
inline std::u16string | to_u16string (format fmt=format::decimal) const |
Converts the uint128_t value to a string representation. | |
inline std::u32string | to_u32string (format fmt=format::decimal) const |
Converts the uint128_t value to a string representation. | |
inline std::u8string | to_u8string (format fmt=format::decimal) const |
Converts the uint128_t value to a string representation. | |
constexpr inline | operator bool () const noexcept |
Checks if the uint128_t value is non-zero. | |
constexpr inline | operator unsigned long long () const noexcept |
Casts the uint128_t value to an integral type. | |
constexpr inline | operator long long () const noexcept |
Casts the uint128_t value to an integral type. | |
constexpr inline | operator unsigned long () const noexcept |
Casts the uint128_t value to an integral type. | |
constexpr inline | operator long () const noexcept |
Casts the uint128_t value to an integral type. | |
constexpr inline | operator unsigned int () const noexcept |
Casts the uint128_t value to an integral type. | |
constexpr inline | operator int () const noexcept |
Casts the uint128_t value to an integral type. | |
constexpr inline | operator unsigned short () const noexcept |
Casts the uint128_t value to an integral type. | |
constexpr inline | operator short () const noexcept |
Casts the uint128_t value to an integral type. | |
constexpr inline | operator unsigned char () const noexcept |
Casts the uint128_t value to an integral type. | |
constexpr inline | operator char () const noexcept |
Casts the uint128_t value to an integral type. | |
constexpr inline | operator signed char () const noexcept |
Casts the uint128_t value to an integral type. | |
inline | operator long double () const noexcept |
Casts the uint128_t value to a floating-point type. | |
inline | operator double () const noexcept |
Casts the uint128_t value to a floating-point type. | |
inline | operator float () const noexcept |
Casts the uint128_t value to a floating-point type. | |
constexpr inline uint128_t & | operator+= (const uint128_t &other) noexcept |
Addition assignment operator. | |
constexpr inline uint128_t & | operator-= (const uint128_t &other) noexcept |
Subtraction assignment operator. | |
constexpr inline uint128_t & | operator*= (const uint128_t &other) noexcept |
Multiplication assignment operator. | |
constexpr inline uint128_t & | operator/= (const uint128_t &other) noexcept |
Division assignment operator. | |
constexpr inline uint128_t & | operator%= (const uint128_t &other) noexcept |
Remainder assignment operator. | |
constexpr inline uint128_t & | operator&= (const uint128_t &other) noexcept |
Bitwise AND assignment operator. | |
constexpr inline uint128_t & | operator|= (const uint128_t &other) noexcept |
Bitwise OR assignment operator. | |
constexpr inline uint128_t & | operator^= (const uint128_t &other) noexcept |
Bitwise XOR assignment operator. | |
template<typename T , typename = typename std::enable_if<std::is_integral<T>::value, T>::type> | |
constexpr inline uint128_t & | operator<<= (T shift) noexcept |
Bitwise left shift assignment operator. | |
template<typename T , typename = typename std::enable_if<std::is_integral<T>::value, T>::type> | |
constexpr inline uint128_t & | operator>>= (T shift) noexcept |
Bitwise right shift assignment operator. | |
constexpr inline uint128_t | operator+ () const noexcept |
Unary plus operator. | |
constexpr inline uint128_t | operator- () const noexcept |
Unary minus operator. | |
constexpr inline uint128_t | operator~ () const noexcept |
Bitwise NOT operator. | |
constexpr inline uint128_t | operator+ (const uint128_t &other) const noexcept |
Addition operator with another uint128_t instance. | |
constexpr inline uint128_t | operator- (const uint128_t &other) const noexcept |
Subtraction operator with another uint128_t instance. | |
constexpr inline uint128_t | operator* (const uint128_t &other) const noexcept |
Multiplication operator with another uint128_t instance. | |
constexpr inline uint128_t | operator/ (const uint128_t &other) const noexcept |
Division operator with another uint128_t instance. | |
constexpr inline uint128_t | operator% (const uint128_t &other) const noexcept |
Remainder operator with another uint128_t instance. | |
constexpr inline uint128_t | operator& (const uint128_t &other) const noexcept |
Bitwise AND operator with another uint128_t instance. | |
constexpr inline uint128_t | operator| (const uint128_t &other) const noexcept |
Bitwise OR operator with another uint128_t instance. | |
constexpr inline uint128_t | operator^ (const uint128_t &other) const noexcept |
Bitwise XOR operator with another uint128_t instance. | |
template<typename T , typename = typename std::enable_if<std::is_integral<T>::value, T>::type> | |
constexpr inline uint128_t | operator<< (T shift) const noexcept |
Bitwise left shift operator with an integral type. | |
template<typename T , typename = typename std::enable_if<std::is_integral<T>::value, T>::type> | |
constexpr inline uint128_t | operator>> (T shift) const noexcept |
Bitwise right shift operator with an integral type. | |
constexpr inline uint128_t & | operator++ () noexcept |
Pre-increment operator. | |
constexpr inline uint128_t & | operator-- () noexcept |
Pre-decrement operator. | |
constexpr inline uint128_t | operator++ (int) noexcept |
Post-increment operator. | |
constexpr inline uint128_t | operator-- (int) noexcept |
Post-decrement operator. | |
constexpr inline bool | operator! () const noexcept |
Logical NOT operator. | |
constexpr inline bool | operator&& (const uint128_t &other) const noexcept |
Logical AND operator. | |
constexpr inline bool | operator|| (const uint128_t &other) const noexcept |
Logical OR operator. | |
template<typename T , typename = typename std::enable_if<std::is_integral<T>::value, T>::type> | |
constexpr inline bool | operator== (T lower) const noexcept |
Equality operator with an integral type. | |
constexpr inline bool | operator== (const uint128_t &other) const noexcept |
Equality operator with another uint128_t instance. | |
template<typename T , typename = typename std::enable_if<std::is_integral<T>::value, T>::type> | |
constexpr inline bool | operator!= (T lower) const noexcept |
Inequality operator with an integral type. | |
constexpr inline bool | operator!= (const uint128_t &other) const noexcept |
Inequality operator with another uint128_t instance. | |
template<typename T , typename = typename std::enable_if<std::is_integral<T>::value, T>::type> | |
constexpr inline bool | operator< (T lower) const noexcept |
Less than operator with an integral type. | |
constexpr inline bool | operator< (const uint128_t &other) const noexcept |
Less than operator with another uint128_t instance. | |
template<typename T , typename = typename std::enable_if<std::is_integral<T>::value, T>::type> | |
constexpr inline bool | operator> (T lower) const noexcept |
Greater than operator with an integral type. | |
constexpr inline bool | operator> (const uint128_t &other) const noexcept |
Greater than operator with another uint128_t instance. | |
template<typename T , typename = typename std::enable_if<std::is_integral<T>::value, T>::type> | |
constexpr inline bool | operator<= (T lower) const noexcept |
Less than or equal to operator with an integral type. | |
constexpr inline bool | operator<= (const uint128_t &other) const noexcept |
Less than or equal to operator with another uint128_t instance. | |
template<typename T , typename = typename std::enable_if<std::is_integral<T>::value, T>::type> | |
constexpr inline bool | operator>= (T lower) const noexcept |
Greater than or equal to operator with an integral type. | |
constexpr inline bool | operator>= (const uint128_t &other) const noexcept |
Greater than or equal to operator with another uint128_t instance. | |
Static Public Member Functions | |
static inline optional< uint128_t > | from_string (const std::string &str, format fmt=format::decimal) noexcept |
Parses a string to a uint128_t instance. | |
static inline optional< uint128_t > | from_string (const std::wstring &str, format fmt=format::decimal) noexcept |
Parses a string to a uint128_t instance. | |
static inline optional< uint128_t > | from_string (const std::u16string &str, format fmt=format::decimal) noexcept |
Parses a string to a uint128_t instance. | |
static inline optional< uint128_t > | from_string (const std::u32string &str, format fmt=format::decimal) noexcept |
Parses a string to a uint128_t instance. | |
static inline optional< uint128_t > | from_string (const std::u8string &str, format fmt=format::decimal) noexcept |
Parses a string to a uint128_t instance. | |
template<typename T , size_t N> | |
static constexpr inline optional< uint128_t > | from_string (const T(&str)[N], format fmt=format::decimal) noexcept |
Parses a string to a uint128_t instance. | |
Class for representing a 128-bit unsigned integer.
uint128_t
offers a comprehensive suite of operations and utilities for handling 128-bit unsigned integers. It supports basic arithmetic operations, bitwise logic, comparison operators, and specialized functions for advanced integer manipulation. The class is optimized for both space and time efficiency, ensuring minimal overhead and maximum performance.
The design of uint128_t
is focused on ease of use and integration. It provides constructors for seamless conversion from built-in integer types, as well as explicit methods for converting to and from other numeric representations. The class also includes support for standard library features like hashing and optional values, enhancing its utility in a wide range of programming scenarios.
The implementation is based on algorithms from the .NET UInt128
structure, ensuring reliable and efficient operations.
|
strong |
Enumerates the string formats available for uint128_t
.
This enumeration defines the possible string representations of uint128_t
values. It allows users to specify the desired format when converting uint128_t
instances to strings.
Enumerator | |
---|---|
decimal | Represents the number in decimal format. This is the default format. |
octal | Represents the number in octal format. |
hexadecimal | Represents the number in hexadecimal format. |
|
defaultnoexcept |
Default constructor.
Constructs a new uint128_t
instance with default values.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Constructs a uint128_t
instance from a signed integer.
This constructor initializes a uint128_t
instance using a signed integer, setting it as the lower part of the uint128_t
value and extending the sign to the upper part.
[in] | lower | The signed integer to initialize the uint128_t instance with. |
|
inlinenoexcept |
Constructs a uint128_t
instance from a signed integer.
This constructor initializes a uint128_t
instance using a signed integer, setting it as the lower part of the uint128_t
value and extending the sign to the upper part.
[in] | lower | The signed integer to initialize the uint128_t instance with. |
|
inlinenoexcept |
Constructs a uint128_t
instance from a signed integer.
This constructor initializes a uint128_t
instance using a signed integer, setting it as the lower part of the uint128_t
value and extending the sign to the upper part.
[in] | lower | The signed integer to initialize the uint128_t instance with. |
|
inlinenoexcept |
Constructs a uint128_t
instance from a signed integer.
This constructor initializes a uint128_t
instance using a signed integer, setting it as the lower part of the uint128_t
value and extending the sign to the upper part.
[in] | lower | The signed integer to initialize the uint128_t instance with. |
|
inlineexplicitnoexcept |
Constructs a uint128_t
instance from a floating-point value.
This constructor initializes a uint128_t
instance by converting a floating-point value to its 128-bit unsigned integer representation. The conversion is explicit to prevent unintended implicit conversions.
[in] | value | The floating-point value to convert. |
|
inlineexplicitnoexcept |
Constructs a uint128_t
instance from a floating-point value.
This constructor initializes a uint128_t
instance by converting a floating-point value to its 128-bit unsigned integer representation. The conversion is explicit to prevent unintended implicit conversions.
[in] | value | The floating-point value to convert. |
|
inlineexplicitnoexcept |
Constructs a uint128_t
instance from a floating-point value.
This constructor initializes a uint128_t
instance by converting a floating-point value to its 128-bit unsigned integer representation. The conversion is explicit to prevent unintended implicit conversions.
[in] | value | The floating-point value to convert. |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |
Converts the uint128_t
value to a string representation.
This method converts the uint128_t
instance to its string representation in the specified format. It supports decimal, octal, and hexadecimal formats.
[in] | fmt | The format to use for the conversion, with format::decimal as the default. |
std::string
holding the converted value.
|
inline |
Converts the uint128_t
value to a string representation.
This method converts the uint128_t
instance to its string representation in the specified format. It supports decimal, octal, and hexadecimal formats.
[in] | fmt | The format to use for the conversion, with format::decimal as the default. |
std::wstring
holding the converted value.
|
inline |
Converts the uint128_t
value to a string representation.
This method converts the uint128_t
instance to its string representation in the specified format. It supports decimal, octal, and hexadecimal formats.
[in] | fmt | The format to use for the conversion, with format::decimal as the default. |
std::u16string
holding the converted value.
|
inline |
Converts the uint128_t
value to a string representation.
This method converts the uint128_t
instance to its string representation in the specified format. It supports decimal, octal, and hexadecimal formats.
[in] | fmt | The format to use for the conversion, with format::decimal as the default. |
std::u32string
holding the converted value.
|
inline |
Converts the uint128_t
value to a string representation.
This method converts the uint128_t
instance to its string representation in the specified format. It supports decimal, octal, and hexadecimal formats.
[in] | fmt | The format to use for the conversion, with format::decimal as the default. |
std::u8string
holding the converted value.
|
inlinestaticnoexcept |
Parses a string to a uint128_t
instance.
This static method attempts to parse a given string as a uint128_t
value in the specified format. If the parsing is successful, it returns an optional containing the parsed uint128_t
value.
[in] | str | The input string to parse. |
[in] | fmt | The string format to interpret the input string (defaults to decimal). |
uint128_t
value if successful, otherwise an empty optional.
|
inlinestaticnoexcept |
Parses a string to a uint128_t
instance.
This static method attempts to parse a given string as a uint128_t
value in the specified format. If the parsing is successful, it returns an optional containing the parsed uint128_t
value.
[in] | str | The input string to parse. |
[in] | fmt | The string format to interpret the input string (defaults to decimal). |
uint128_t
value if successful, otherwise an empty optional.
|
inlinestaticnoexcept |
Parses a string to a uint128_t
instance.
This static method attempts to parse a given string as a uint128_t
value in the specified format. If the parsing is successful, it returns an optional containing the parsed uint128_t
value.
[in] | str | The input string to parse. |
[in] | fmt | The string format to interpret the input string (defaults to decimal). |
uint128_t
value if successful, otherwise an empty optional.
|
inlinestaticnoexcept |
Parses a string to a uint128_t
instance.
This static method attempts to parse a given string as a uint128_t
value in the specified format. If the parsing is successful, it returns an optional containing the parsed uint128_t
value.
[in] | str | The input string to parse. |
[in] | fmt | The string format to interpret the input string (defaults to decimal). |
uint128_t
value if successful, otherwise an empty optional.
|
inlinestaticnoexcept |
Parses a string to a uint128_t
instance.
This static method attempts to parse a given string as a uint128_t
value in the specified format. If the parsing is successful, it returns an optional containing the parsed uint128_t
value.
[in] | str | The input string to parse. |
[in] | fmt | The string format to interpret the input string (defaults to decimal). |
uint128_t
value if successful, otherwise an empty optional.
|
inlinestaticnoexcept |
Parses a string to a uint128_t
instance.
This static method attempts to parse a given string as a uint128_t
value in the specified format. If the parsing is successful, it returns an optional containing the parsed uint128_t
value.
T | The character type of the array. |
N | The size of the character array. |
[in] | str | The input string to parse. |
[in] | fmt | The string format to interpret the input string (defaults to decimal). |
uint128_t
value if successful, otherwise an empty optional.
|
inlineexplicitnoexcept |
|
inlineexplicitnoexcept |
|
inlineexplicitnoexcept |
|
inlineexplicitnoexcept |
|
inlineexplicitnoexcept |
|
inlineexplicitnoexcept |
|
inlineexplicitnoexcept |
|
inlineexplicitnoexcept |
|
inlineexplicitnoexcept |
|
inlineexplicitnoexcept |
|
inlineexplicitnoexcept |
|
inlineexplicitnoexcept |
|
inlineexplicitnoexcept |
|
inlineexplicitnoexcept |
|
inlineexplicitnoexcept |
Bitwise AND assignment operator.
Performs a bitwise AND operation between this instance and another uint128_t
instance and assigns the result to this instance.
[in] | other | The uint128_t instance to perform the bitwise AND with. |
Bitwise OR assignment operator.
Performs a bitwise OR operation between this instance and another uint128_t
instance and assigns the result to this instance.
[in] | other | The uint128_t instance to perform the bitwise OR with. |
Bitwise XOR assignment operator.
Performs a bitwise XOR operation between this instance and another uint128_t
instance and assigns the result to this instance.
[in] | other | The uint128_t instance to perform the bitwise XOR with. |
|
inlinenoexcept |
Bitwise left shift assignment operator.
Shifts the bits of this instance to the left by the specified number of places and assigns the result to this instance.
T | An integral type representing the number of places to shift. |
[in] | shift | The number of bits to shift to the left. |
|
inlinenoexcept |
Bitwise right shift assignment operator.
Shifts the bits of this instance to the right by the specified number of places and assigns the result to this instance.
T | An integral type representing the number of places to shift. |
[in] | shift | The number of bits to shift to the right. |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Remainder operator with another uint128_t
instance.
Calculates the remainder of this instance divided by another uint128_t
instance and returns a new uint128_t
instance with the result.
[in] | other | The uint128_t instance to divide by. |
uint128_t
instance representing the remainder. Bitwise AND operator with another uint128_t
instance.
Performs a bitwise AND operation between this instance and another uint128_t
instance and returns a new uint128_t
instance with the result.
[in] | other | The uint128_t instance to perform the bitwise AND with. |
uint128_t
instance representing the result of the bitwise AND operation. Bitwise OR operator with another uint128_t
instance.
Performs a bitwise OR operation between this instance and another uint128_t
instance and returns a new uint128_t
instance with the result.
[in] | other | The uint128_t instance to perform the bitwise OR with. |
uint128_t
instance representing the result of the bitwise OR operation. Bitwise XOR operator with another uint128_t
instance.
Performs a bitwise XOR operation between this instance and another uint128_t
instance and returns a new uint128_t
instance with the result.
[in] | other | The uint128_t instance to perform the bitwise XOR with. |
uint128_t
instance representing the result of the bitwise XOR operation.
|
inlinenoexcept |
Bitwise left shift operator with an integral type.
Shifts the bits of this instance to the left by the specified number of places and returns a new uint128_t
instance with the result.
T | An integral type representing the number of places to shift. |
[in] | shift | The number of bits to shift to the left. |
uint128_t
instance representing the result of the left shift operation.
|
inlinenoexcept |
Bitwise right shift operator with an integral type.
Shifts the bits of this instance to the right by the specified number of places and returns a new uint128_t
instance with the result.
T | An integral type representing the number of places to shift. |
[in] | shift | The number of bits to shift to the right. |
uint128_t
instance representing the result of the right shift operation.
|
inlinenoexcept |
Pre-increment operator.
Increments this instance by one and returns a reference to this instance.
|
inlinenoexcept |
Pre-decrement operator.
Decrements this instance by one and returns a reference to this instance.
|
inlinenoexcept |
Post-increment operator.
Increments this instance by one and returns the value of the instance before the increment.
|
inlinenoexcept |
Post-decrement operator.
Decrements this instance by one and returns the value of the instance before the decrement.
|
inlinenoexcept |
Logical NOT operator.
Returns true
if this instance is zero, otherwise returns false
.
true
if this instance is zero, false
otherwise.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Equality operator with an integral type.
Compares this instance to an integral value for equality.
T | An integral type to compare with. |
[in] | lower | The integral value to compare with. |
true
if this instance is equal to the integral value, false
otherwise.
|
inlinenoexcept |
|
inlinenoexcept |
Inequality operator with an integral type.
Compares this instance to an integral value for inequality.
T | An integral type to compare with. |
[in] | lower | The integral value to compare with. |
true
if this instance is not equal to the integral value, false
otherwise.
|
inlinenoexcept |
Less than operator with an integral type.
Checks if the value of this instance is lexicographically less than the provided integral value.
T | An integral type to compare with. |
[in] | lower | The integral value to compare with. |
true
if this instance is less than the integral value, false
otherwise.
|
inlinenoexcept |
|
inlinenoexcept |
Greater than operator with an integral type.
Checks if the value of this instance is lexicographically greater than the provided integral value.
T | An integral type to compare with. |
[in] | lower | The integral value to compare with. |
true
if this instance is greater than the integral value, false
otherwise.
|
inlinenoexcept |
Greater than operator with another uint128_t
instance.
Checks if the value of this instance is lexicographically greater than the provided uint128_t
instance.
[in] | other | The uint128_t instance to compare with. |
true
if this instance is greater than the other instance, false
otherwise.
|
inlinenoexcept |
Less than or equal to operator with an integral type.
Checks if the value of this instance is lexicographically less than or equal to the provided integral value.
T | An integral type to compare with. |
[in] | lower | The integral value to compare with. |
true
if this instance is less than or equal to the integral value, false
otherwise.
|
inlinenoexcept |
Less than or equal to operator with another uint128_t
instance.
Checks if the value of this instance is lexicographically less than or equal to the provided uint128_t
instance.
[in] | other | The uint128_t instance to compare with. |
true
if this instance is less than or equal to the other instance, false
otherwise.
|
inlinenoexcept |
Greater than or equal to operator with an integral type.
Checks if the value of this instance is lexicographically greater than or equal to the provided integral value.
T | An integral type to compare with. |
[in] | lower | The integral value to compare with. |
true
if this instance is greater than or equal to the integral value, false
otherwise.
|
inlinenoexcept |
Greater than or equal to operator with another uint128_t
instance.
Checks if the value of this instance is lexicographically greater than or equal to the provided uint128_t
instance.
[in] | other | The uint128_t instance to compare with. |
true
if this instance is greater than or equal to the other instance, false
otherwise.