diff --git a/src/entt/core/hashed_string.hpp b/src/entt/core/hashed_string.hpp index 7531b0667..6a8e12f55 100644 --- a/src/entt/core/hashed_string.hpp +++ b/src/entt/core/hashed_string.hpp @@ -71,7 +71,7 @@ class basic_hashed_string { }; // Fowler–Noll–Vo hash function v. 1a - the good - static constexpr id_type helper(const Char *curr) ENTT_NOEXCEPT { + [[nodiscard]] static constexpr id_type helper(const Char *curr) ENTT_NOEXCEPT { auto value = traits_type::offset; while(*curr != 0) { @@ -103,7 +103,7 @@ public: * @return The numeric representation of the string. */ template - static constexpr hash_type value(const value_type (&str)[N]) ENTT_NOEXCEPT { + [[nodiscard]] static constexpr hash_type value(const value_type (&str)[N]) ENTT_NOEXCEPT { return helper(str); } @@ -112,7 +112,7 @@ public: * @param wrapper Helps achieving the purpose by relying on overloading. * @return The numeric representation of the string. */ - static hash_type value(const_wrapper wrapper) ENTT_NOEXCEPT { + [[nodiscard]] static hash_type value(const_wrapper wrapper) ENTT_NOEXCEPT { return helper(wrapper.str); } @@ -122,7 +122,7 @@ public: * @param size Length of the string to hash. * @return The numeric representation of the string. */ - static hash_type value(const value_type *str, std::size_t size) ENTT_NOEXCEPT { + [[nodiscard]] static hash_type value(const value_type *str, std::size_t size) ENTT_NOEXCEPT { id_type partial{traits_type::offset}; while(size--) { partial = (partial^(str++)[0])*traits_type::prime; } return partial; @@ -165,7 +165,7 @@ public: * @brief Returns the human-readable representation of a hashed string. * @return The string used to initialize the instance. */ - constexpr const value_type * data() const ENTT_NOEXCEPT { + [[nodiscard]] constexpr const value_type * data() const ENTT_NOEXCEPT { return str; } @@ -173,25 +173,25 @@ public: * @brief Returns the numeric representation of a hashed string. * @return The numeric representation of the instance. */ - constexpr hash_type value() const ENTT_NOEXCEPT { + [[nodiscard]] constexpr hash_type value() const ENTT_NOEXCEPT { return hash; } /*! @copydoc data */ - constexpr operator const value_type *() const ENTT_NOEXCEPT { return data(); } + [[nodiscard]] constexpr operator const value_type *() const ENTT_NOEXCEPT { return data(); } /** * @brief Returns the numeric representation of a hashed string. * @return The numeric representation of the instance. */ - constexpr operator hash_type() const ENTT_NOEXCEPT { return value(); } + [[nodiscard]] constexpr operator hash_type() const ENTT_NOEXCEPT { return value(); } /** * @brief Compares two hashed strings. * @param other Hashed string with which to compare. * @return True if the two hashed strings are identical, false otherwise. */ - constexpr bool operator==(const basic_hashed_string &other) const ENTT_NOEXCEPT { + [[nodiscard]] constexpr bool operator==(const basic_hashed_string &other) const ENTT_NOEXCEPT { return hash == other.hash; } @@ -224,7 +224,7 @@ basic_hashed_string(const Char (&str)[N]) ENTT_NOEXCEPT * @return True if the two hashed strings are identical, false otherwise. */ template -constexpr bool operator!=(const basic_hashed_string &lhs, const basic_hashed_string &rhs) ENTT_NOEXCEPT { +[[nodiscard]] constexpr bool operator!=(const basic_hashed_string &lhs, const basic_hashed_string &rhs) ENTT_NOEXCEPT { return !(lhs == rhs); } @@ -245,7 +245,7 @@ using hashed_wstring = basic_hashed_string; * @param str The literal without its suffix. * @return A properly initialized hashed string. */ -constexpr entt::hashed_string operator"" ENTT_HS_SUFFIX(const char *str, std::size_t) ENTT_NOEXCEPT { +[[nodiscard]] constexpr entt::hashed_string operator"" ENTT_HS_SUFFIX(const char *str, std::size_t) ENTT_NOEXCEPT { return entt::hashed_string{str}; } @@ -255,7 +255,7 @@ constexpr entt::hashed_string operator"" ENTT_HS_SUFFIX(const char *str, std::si * @param str The literal without its suffix. * @return A properly initialized hashed wstring. */ -constexpr entt::hashed_wstring operator"" ENTT_HWS_SUFFIX(const wchar_t *str, std::size_t) ENTT_NOEXCEPT { +[[nodiscard]] constexpr entt::hashed_wstring operator"" ENTT_HWS_SUFFIX(const wchar_t *str, std::size_t) ENTT_NOEXCEPT { return entt::hashed_wstring{str}; } diff --git a/src/entt/core/ident.hpp b/src/entt/core/ident.hpp index 984ad2a01..799c45fae 100644 --- a/src/entt/core/ident.hpp +++ b/src/entt/core/ident.hpp @@ -45,7 +45,7 @@ class identifier { using tuple_type = std::tuple...>; template - static constexpr id_type get(std::index_sequence) { + [[nodiscard]] static constexpr id_type get(std::index_sequence) { static_assert(std::disjunction_v...>, "Invalid type"); return (0 + ... + (std::is_same_v> ? id_type(Indexes) : id_type{})); } diff --git a/src/entt/core/monostate.hpp b/src/entt/core/monostate.hpp index e25dd5313..582d03f55 100644 --- a/src/entt/core/monostate.hpp +++ b/src/entt/core/monostate.hpp @@ -38,7 +38,7 @@ struct monostate { * @return Stored value, if any. */ template - operator Type() const ENTT_NOEXCEPT { + [[nodiscard]] operator Type() const ENTT_NOEXCEPT { return value; } diff --git a/src/entt/core/type_info.hpp b/src/entt/core/type_info.hpp index 1510ddddd..f755e9143 100644 --- a/src/entt/core/type_info.hpp +++ b/src/entt/core/type_info.hpp @@ -22,7 +22,7 @@ namespace internal { struct ENTT_API type_index { - static id_type next() ENTT_NOEXCEPT { + [[nodiscard]] static id_type next() ENTT_NOEXCEPT { static ENTT_MAYBE_ATOMIC(id_type) value{}; return value++; } @@ -30,7 +30,7 @@ struct ENTT_API type_index { template -constexpr auto type_name() ENTT_NOEXCEPT { +[[nodiscard]] constexpr auto type_name() ENTT_NOEXCEPT { #if defined ENTT_PRETTY_FUNCTION std::string_view pretty_function{ENTT_PRETTY_FUNCTION}; auto first = pretty_function.find_first_not_of(' ', pretty_function.find_first_of(ENTT_PRETTY_FUNCTION_PREFIX)+1); @@ -61,7 +61,7 @@ struct ENTT_API type_index { * @brief Returns the sequential identifier of a given type. * @return The sequential identifier of a given type. */ - static id_type value() ENTT_NOEXCEPT { + [[nodiscard]] static id_type value() ENTT_NOEXCEPT { static const id_type value = internal::type_index::next(); return value; } @@ -101,17 +101,17 @@ struct type_info { * @return The numeric representation of the given type. */ #if defined ENTT_PRETTY_FUNCTION_CONSTEXPR - static constexpr id_type id() ENTT_NOEXCEPT { + [[nodiscard]] static constexpr id_type id() ENTT_NOEXCEPT { constexpr auto value = entt::hashed_string::value(ENTT_PRETTY_FUNCTION); return value; } #elif defined ENTT_PRETTY_FUNCTION - static id_type id() ENTT_NOEXCEPT { + [[nodiscard]] static id_type id() ENTT_NOEXCEPT { static const auto value = entt::hashed_string::value(ENTT_PRETTY_FUNCTION); return value; } #else - static id_type id() ENTT_NOEXCEPT { + [[nodiscard]] static id_type id() ENTT_NOEXCEPT { return type_index::value(); } #endif @@ -121,17 +121,17 @@ struct type_info { * @return The name of the given type. */ #if defined ENTT_PRETTY_FUNCTION_CONSTEXPR - static constexpr std::string_view name() ENTT_NOEXCEPT { + [[nodiscard]] static constexpr std::string_view name() ENTT_NOEXCEPT { constexpr auto value = internal::type_name(); return value; } #elif defined ENTT_PRETTY_FUNCTION - static std::string_view name() ENTT_NOEXCEPT { + [[nodiscard]] static std::string_view name() ENTT_NOEXCEPT { static const auto value = internal::type_name(); return value; } #else - static constexpr std::string_view name() ENTT_NOEXCEPT { + [[nodiscard]] static constexpr std::string_view name() ENTT_NOEXCEPT { return internal::type_name(); } #endif diff --git a/src/entt/core/type_traits.hpp b/src/entt/core/type_traits.hpp index f3c4bb835..c73ff56ea 100644 --- a/src/entt/core/type_traits.hpp +++ b/src/entt/core/type_traits.hpp @@ -6,7 +6,6 @@ #include #include #include "../config/config.h" -#include "hashed_string.hpp" #include "fwd.hpp" @@ -235,7 +234,7 @@ using member_class_t = typename member_class::type; * @param id The value to convert.\ * @return The integral representation of the given value. */\ - constexpr auto to_integral(const clazz id) ENTT_NOEXCEPT {\ + [[nodiscard]] constexpr auto to_integral(const clazz id) ENTT_NOEXCEPT {\ return static_cast>(id);\ }\ static_assert(true) diff --git a/src/entt/core/utility.hpp b/src/entt/core/utility.hpp index 1092de856..5a7ec16a9 100644 --- a/src/entt/core/utility.hpp +++ b/src/entt/core/utility.hpp @@ -18,7 +18,7 @@ struct identity { * @return The submitted value as-is. */ template - constexpr Type && operator()(Type &&value) const ENTT_NOEXCEPT { + [[nodiscard]] constexpr Type && operator()(Type &&value) const ENTT_NOEXCEPT { return std::forward(value); } }; @@ -32,7 +32,7 @@ struct identity { * @return Pointer to the member. */ template -constexpr auto overload(Type Class:: *member) ENTT_NOEXCEPT { return member; } +[[nodiscard]] constexpr auto overload(Type Class:: *member) ENTT_NOEXCEPT { return member; } /** @@ -42,7 +42,7 @@ constexpr auto overload(Type Class:: *member) ENTT_NOEXCEPT { return member; } * @return Pointer to the function. */ template -constexpr auto overload(Func *func) ENTT_NOEXCEPT { return func; } +[[nodiscard]] constexpr auto overload(Func *func) ENTT_NOEXCEPT { return func; } /**