Skip to content

Commit

Permalink
hashed string: apply consteval on appropriate basic_hashed_string rel…
Browse files Browse the repository at this point in the history
…ated functions (#1203)
  • Loading branch information
DNKpp authored Jan 17, 2025
1 parent 3c5e77e commit 12b0a86
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src/entt/config/macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@
#define ENTT_STR(arg) #arg
#define ENTT_XSTR(arg) ENTT_STR(arg)

#define ENTT_CONSTEVAL constexpr

#if __has_include(<version>)
# include <version>
#
# if defined(__cpp_consteval)
# undef ENTT_CONSTEVAL
# define ENTT_CONSTEVAL consteval
# endif
#endif

// NOLINTEND(cppcoreguidelines-macro-usage)

#endif
8 changes: 4 additions & 4 deletions src/entt/core/hashed_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class basic_hashed_string: internal::basic_hashed_string<Char> {
*/
template<std::size_t N>
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, modernize-avoid-c-arrays)
[[nodiscard]] static constexpr hash_type value(const value_type (&str)[N]) noexcept {
[[nodiscard]] static ENTT_CONSTEVAL hash_type value(const value_type (&str)[N]) noexcept {
return basic_hashed_string{str};
}

Expand Down Expand Up @@ -137,7 +137,7 @@ class basic_hashed_string: internal::basic_hashed_string<Char> {
*/
template<std::size_t N>
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, modernize-avoid-c-arrays)
constexpr basic_hashed_string(const value_type (&str)[N]) noexcept
ENTT_CONSTEVAL basic_hashed_string(const value_type (&str)[N]) noexcept
: base_type{helper({static_cast<const value_type *>(str)})} {}

/**
Expand Down Expand Up @@ -291,7 +291,7 @@ inline namespace literals {
* @param str The literal without its suffix.
* @return A properly initialized hashed string.
*/
[[nodiscard]] constexpr hashed_string operator""_hs(const char *str, std::size_t) noexcept {
[[nodiscard]] ENTT_CONSTEVAL hashed_string operator""_hs(const char *str, std::size_t) noexcept {
return hashed_string{str};
}

Expand All @@ -300,7 +300,7 @@ inline namespace literals {
* @param str The literal without its suffix.
* @return A properly initialized hashed wstring.
*/
[[nodiscard]] constexpr hashed_wstring operator""_hws(const wchar_t *str, std::size_t) noexcept {
[[nodiscard]] ENTT_CONSTEVAL hashed_wstring operator""_hws(const wchar_t *str, std::size_t) noexcept {
return hashed_wstring{str};
}

Expand Down

0 comments on commit 12b0a86

Please sign in to comment.