From e9d36a6237aeef5bb29db9955313910a6b181eed Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Thu, 27 Feb 2020 17:30:31 +0100 Subject: [PATCH] Better handling of Windows not handling constexpr on std::string. --- src/__ConstStringCore.hpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/__ConstStringCore.hpp b/src/__ConstStringCore.hpp index f83f752..1691a0f 100644 --- a/src/__ConstStringCore.hpp +++ b/src/__ConstStringCore.hpp @@ -2,13 +2,9 @@ #define ARBUTILS_CONSTSTRINGCORE_HPP #if WINDOWS -#define STDSTRINGEQUALITY \ - inline bool operator==(const std::string& rhs) const { return _hash == Hash(rhs.c_str()); } \ - inline bool operator!=(const std::string& rhs) const { return _hash != Hash(rhs.c_str()); } +#define STDSTRINGCONSTEXPR #else -#define STDSTRINGEQUALITY \ - inline constexpr bool operator==(const std::string& rhs) const { return _hash == Hash(rhs.c_str()); } \ - inline constexpr bool operator!=(const std::string& rhs) const { return _hash != Hash(rhs.c_str()); } +#define STDSTRINGCONSTEXPR constexpr #endif #define ConstStringCore(name, hashFunction) \ @@ -26,7 +22,7 @@ public: \ constexpr name() : _str(""), _length(0), _hash(Hash("")){}; \ constexpr explicit name(const char* str) : _str(str), _length(Length(str)), _hash(Hash(str)){}; \ - constexpr explicit name(const std::string& str) \ + STDSTRINGCONSTEXPR explicit name(const std::string& str) \ : _str(str.c_str()), _length(str.length()), _hash(Hash(str.c_str())){}; \ constexpr explicit name(const char* str, size_t size) : _str(str), _length(size), _hash(Hash(str)){}; \ \ @@ -42,7 +38,10 @@ \ inline constexpr bool operator==(const name& rhs) const { return _hash == rhs._hash; } \ inline constexpr bool operator!=(const name& rhs) const { return _hash != rhs._hash; } \ - STDSTRINGEQUALITY \ + inline STDSTRINGCONSTEXPR bool operator==(const std::string& rhs) const { \ + return _hash == Hash(rhs.c_str()); } \ + inline STDSTRINGCONSTEXPR bool operator!=(const std::string& rhs) const { \ + return _hash != Hash(rhs.c_str()); } \ inline constexpr bool operator==(const char* rhs) const { return _hash == Hash(rhs); } \ inline constexpr bool operator!=(const char* rhs) const { return _hash != Hash(rhs); } \ }; \