From 805244f796285087d9d5c70ece5a015c67c99b31 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 24 Feb 2019 09:36:04 -0600 Subject: [PATCH] [ox/std] Add nodiscard to bitops, byteswap, and strops --- deps/ox/src/ox/std/bitops.hpp | 4 ++-- deps/ox/src/ox/std/byteswap.hpp | 10 +++++----- deps/ox/src/ox/std/strops.hpp | 20 ++++++++++---------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/deps/ox/src/ox/std/bitops.hpp b/deps/ox/src/ox/std/bitops.hpp index 70b2bf7b..187b67ae 100644 --- a/deps/ox/src/ox/std/bitops.hpp +++ b/deps/ox/src/ox/std/bitops.hpp @@ -11,13 +11,13 @@ namespace ox { template -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 -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(1) << i; diff --git a/deps/ox/src/ox/std/byteswap.hpp b/deps/ox/src/ox/std/byteswap.hpp index ec25eacc..e048d8ad 100644 --- a/deps/ox/src/ox/std/byteswap.hpp +++ b/deps/ox/src/ox/std/byteswap.hpp @@ -15,17 +15,17 @@ namespace ox { template -constexpr inline T byteSwap(typename enable_if::type i) noexcept { +[[nodiscard]] constexpr inline T byteSwap(typename enable_if::type i) noexcept { return i; } template -constexpr inline T byteSwap(typename enable_if::type i) noexcept { +[[nodiscard]] constexpr inline T byteSwap(typename enable_if::type i) noexcept { return (i << 8) | (i >> 8); } template -constexpr inline T byteSwap(typename enable_if::type i) noexcept { +[[nodiscard]] constexpr inline T byteSwap(typename enable_if::type i) noexcept { return ((i >> 24) & 0x000000ff) | ((i >> 8) & 0x0000ff00) | ((i << 8) & 0x00ff0000) | @@ -33,7 +33,7 @@ constexpr inline T byteSwap(typename enable_if::type i) noexc } template -constexpr inline T byteSwap(typename enable_if::type i) noexcept { +[[nodiscard]] constexpr inline T byteSwap(typename enable_if::type i) noexcept { return ((i >> 56) & 0x00000000000000ff) | ((i >> 40) & 0x000000000000ff00) | ((i >> 24) & 0x0000000000ff0000) | @@ -49,7 +49,7 @@ constexpr inline T byteSwap(typename enable_if::type i) noexc * Takes an int and byte swaps if the platform is the given condition is true. */ template -constexpr inline T conditionalByteSwap(T i) noexcept { +[[nodiscard]] constexpr inline T conditionalByteSwap(T i) noexcept { if constexpr(byteSwap) { return ox::byteSwap(i); } else { diff --git a/deps/ox/src/ox/std/strops.hpp b/deps/ox/src/ox/std/strops.hpp index 93b5d709..493365ca 100644 --- a/deps/ox/src/ox/std/strops.hpp +++ b/deps/ox/src/ox/std/strops.hpp @@ -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 -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 -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 -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;