Better handling of Windows not handling constexpr on std::string.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-02-27 17:30:31 +01:00
parent 7d6ec6f5a6
commit e9d36a6237
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
1 changed files with 7 additions and 8 deletions

View File

@ -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); } \
}; \