[ox/std] Add nodiscard to bitops, byteswap, and strops
This commit is contained in:
parent
5a1d1c0a2f
commit
805244f796
4
deps/ox/src/ox/std/bitops.hpp
vendored
4
deps/ox/src/ox/std/bitops.hpp
vendored
@ -11,13 +11,13 @@
|
||||
namespace ox {
|
||||
|
||||
template<typename T>
|
||||
inline constexpr T rotateLeft(T i, int shift) {
|
||||
[[nodiscard]] inline constexpr T rotateLeft(T i, int shift) {
|
||||
constexpr auto bits = sizeof(i) * 8;
|
||||
return (i << shift) | (i >> (bits - shift));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr T onMask(int bits = sizeof(T) * 8) {
|
||||
[[nodiscard]] constexpr T onMask(int bits = sizeof(T) * 8) {
|
||||
T out = 0;
|
||||
for (auto i = 0; i < bits; i++) {
|
||||
out |= static_cast<T>(1) << i;
|
||||
|
10
deps/ox/src/ox/std/byteswap.hpp
vendored
10
deps/ox/src/ox/std/byteswap.hpp
vendored
@ -15,17 +15,17 @@
|
||||
namespace ox {
|
||||
|
||||
template<typename T>
|
||||
constexpr inline T byteSwap(typename enable_if<sizeof(T) == 1, T>::type i) noexcept {
|
||||
[[nodiscard]] constexpr inline T byteSwap(typename enable_if<sizeof(T) == 1, T>::type i) noexcept {
|
||||
return i;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr inline T byteSwap(typename enable_if<sizeof(T) == 2, T>::type i) noexcept {
|
||||
[[nodiscard]] constexpr inline T byteSwap(typename enable_if<sizeof(T) == 2, T>::type i) noexcept {
|
||||
return (i << 8) | (i >> 8);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr inline T byteSwap(typename enable_if<sizeof(T) == 4, T>::type i) noexcept {
|
||||
[[nodiscard]] constexpr inline T byteSwap(typename enable_if<sizeof(T) == 4, T>::type i) noexcept {
|
||||
return ((i >> 24) & 0x000000ff) |
|
||||
((i >> 8) & 0x0000ff00) |
|
||||
((i << 8) & 0x00ff0000) |
|
||||
@ -33,7 +33,7 @@ constexpr inline T byteSwap(typename enable_if<sizeof(T) == 4, T>::type i) noexc
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr inline T byteSwap(typename enable_if<sizeof(T) == 8, T>::type i) noexcept {
|
||||
[[nodiscard]] constexpr inline T byteSwap(typename enable_if<sizeof(T) == 8, T>::type i) noexcept {
|
||||
return ((i >> 56) & 0x00000000000000ff) |
|
||||
((i >> 40) & 0x000000000000ff00) |
|
||||
((i >> 24) & 0x0000000000ff0000) |
|
||||
@ -49,7 +49,7 @@ constexpr inline T byteSwap(typename enable_if<sizeof(T) == 8, T>::type i) noexc
|
||||
* Takes an int and byte swaps if the platform is the given condition is true.
|
||||
*/
|
||||
template<typename T, bool byteSwap>
|
||||
constexpr inline T conditionalByteSwap(T i) noexcept {
|
||||
[[nodiscard]] constexpr inline T conditionalByteSwap(T i) noexcept {
|
||||
if constexpr(byteSwap) {
|
||||
return ox::byteSwap<T>(i);
|
||||
} else {
|
||||
|
20
deps/ox/src/ox/std/strops.hpp
vendored
20
deps/ox/src/ox/std/strops.hpp
vendored
@ -20,21 +20,21 @@ constexpr char *ox_strncpy(T1 dest, T2 src, std::size_t maxLen) noexcept {
|
||||
return dest;
|
||||
}
|
||||
|
||||
constexpr int ox_strnlen(const char *str1, int maxLen) noexcept {
|
||||
[[nodiscard]] constexpr int ox_strnlen(const char *str1, int maxLen) noexcept {
|
||||
int len = 0;
|
||||
for (; len < maxLen && str1[len]; len++);
|
||||
return len;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr int ox_strlen(T str1) noexcept {
|
||||
[[nodiscard]] constexpr int ox_strlen(T str1) noexcept {
|
||||
int len = 0;
|
||||
for (; str1[len]; len++);
|
||||
return len;
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
constexpr int ox_strcmp(T1 str1, T2 str2) noexcept {
|
||||
[[nodiscard]] constexpr int ox_strcmp(T1 str1, T2 str2) noexcept {
|
||||
auto retval = 0;
|
||||
auto i = 0;
|
||||
while (str1[i] || str2[i]) {
|
||||
@ -50,7 +50,7 @@ constexpr int ox_strcmp(T1 str1, T2 str2) noexcept {
|
||||
return retval;
|
||||
}
|
||||
|
||||
constexpr int ox_strncmp(const char *str1, const char *str2, std::size_t len) noexcept {
|
||||
[[nodiscard]] constexpr int ox_strncmp(const char *str1, const char *str2, std::size_t len) noexcept {
|
||||
auto retval = 0;
|
||||
std::size_t i = 0;
|
||||
while (i < len && (str1[i] || str2[i])) {
|
||||
@ -66,7 +66,7 @@ constexpr int ox_strncmp(const char *str1, const char *str2, std::size_t len) no
|
||||
return retval;
|
||||
}
|
||||
|
||||
constexpr const char *ox_strchr(const char *str, int character, std::size_t maxLen = 0xFFFFFFFF) noexcept {
|
||||
[[nodiscard]] constexpr const char *ox_strchr(const char *str, int character, std::size_t maxLen = 0xFFFFFFFF) noexcept {
|
||||
for (std::size_t i = 0; i <= maxLen; i++) {
|
||||
if (str[i] == character) {
|
||||
return &str[i];
|
||||
@ -77,7 +77,7 @@ constexpr const char *ox_strchr(const char *str, int character, std::size_t maxL
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
constexpr char *ox_strchr(char *str, int character, std::size_t maxLen = 0xFFFFFFFF) noexcept {
|
||||
[[nodiscard]] constexpr char *ox_strchr(char *str, int character, std::size_t maxLen = 0xFFFFFFFF) noexcept {
|
||||
for (std::size_t i = 0; i < maxLen; i++) {
|
||||
if (str[i] == character) {
|
||||
return &str[i];
|
||||
@ -88,7 +88,7 @@ constexpr char *ox_strchr(char *str, int character, std::size_t maxLen = 0xFFFFF
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
constexpr int ox_lastIndexOf(const char *str, int character, int maxLen = 0xFFFFFFFF) noexcept {
|
||||
[[nodiscard]] constexpr int ox_lastIndexOf(const char *str, int character, int maxLen = 0xFFFFFFFF) noexcept {
|
||||
int retval = -1;
|
||||
for (int i = 0; i < maxLen && str[i]; i++) {
|
||||
if (str[i] == character) {
|
||||
@ -98,7 +98,7 @@ constexpr int ox_lastIndexOf(const char *str, int character, int maxLen = 0xFFFF
|
||||
return retval;
|
||||
}
|
||||
|
||||
constexpr int ox_lastIndexOf(char *str, int character, int maxLen = 0xFFFFFFFF) noexcept {
|
||||
[[nodiscard]] constexpr int ox_lastIndexOf(char *str, int character, int maxLen = 0xFFFFFFFF) noexcept {
|
||||
int retval = -1;
|
||||
for (int i = 0; i < maxLen && str[i]; i++) {
|
||||
if (str[i] == character) {
|
||||
@ -108,7 +108,7 @@ constexpr int ox_lastIndexOf(char *str, int character, int maxLen = 0xFFFFFFFF)
|
||||
return retval;
|
||||
}
|
||||
|
||||
constexpr int ox_atoi(const char *str) noexcept {
|
||||
[[nodiscard]] constexpr int ox_atoi(const char *str) noexcept {
|
||||
int total = 0;
|
||||
int multiplier = 1;
|
||||
|
||||
@ -121,7 +121,7 @@ constexpr int ox_atoi(const char *str) noexcept {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr char *ox_itoa(int64_t v, T str) noexcept {
|
||||
constexpr T ox_itoa(int64_t v, T str) noexcept {
|
||||
if (v) {
|
||||
auto mod = 1000000000000000000;
|
||||
constexpr auto base = 10;
|
||||
|
Loading…
Reference in New Issue
Block a user