diff options
| author | Dan Engelbrecht <[email protected]> | 2022-04-01 23:36:24 +0200 |
|---|---|---|
| committer | Dan Engelbrecht <[email protected]> | 2022-04-01 23:36:24 +0200 |
| commit | 047be064076840cdb908f226f34d9f0d1b607a60 (patch) | |
| tree | 566bc8e341d9f069bd1e9b5eb6ee17b03ce57dc0 /zencore/include | |
| parent | safer and easier to read Char2Nibble (diff) | |
| download | zen-047be064076840cdb908f226f34d9f0d1b607a60.tar.xz zen-047be064076840cdb908f226f34d9f0d1b607a60.zip | |
use std::unsigned_integral for ToHexNumber and ParseHexNumber
Diffstat (limited to 'zencore/include')
| -rw-r--r-- | zencore/include/zencore/string.h | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/zencore/include/zencore/string.h b/zencore/include/zencore/string.h index 0aa7771a7..e502120ac 100644 --- a/zencore/include/zencore/string.h +++ b/zencore/include/zencore/string.h @@ -9,6 +9,7 @@ #include <string.h> #include <charconv> #include <codecvt> +#include <concepts> #include <optional> #include <span> #include <string_view> @@ -595,12 +596,11 @@ ToHexNumber(const uint8_t* InputData, size_t ByteCount, char* OutString) /// </summary> /// <param name="Value">Integer value type</param> /// <param name="outString">Output buffer where resulting string is written</param> -template<typename T> void -ToHexNumber(T Value, char* OutString) +ToHexNumber(std::unsigned_integral auto Value, char* OutString) { - ToHexNumber((const uint8_t*)&Value, sizeof(T), OutString); - OutString[sizeof(T) * 2] = 0; + ToHexNumber((const uint8_t*)&Value, sizeof(Value), OutString); + OutString[sizeof(Value) * 2] = 0; } /// <summary> @@ -610,11 +610,10 @@ ToHexNumber(T Value, char* OutString) /// <param name="characterCount">Number of characters in string</param> /// <param name="OutValue">Pointer to output value</param> /// <returns>true if the input consisted of all valid hexadecimal characters</returns> -template<typename T> bool -ParseHexNumber(const std::string HexString, T& OutValue) +ParseHexNumber(const std::string HexString, std::unsigned_integral auto& OutValue) { - return ParseHexNumber(HexString.c_str(), sizeof(T) * 2, (uint8_t*)&OutValue); + return ParseHexNumber(HexString.c_str(), sizeof(OutValue) * 2, (uint8_t*)&OutValue); } ////////////////////////////////////////////////////////////////////////// |