Static assert that LiteralStringRef arg is literal string
This commit is contained in:
parent
f0bc23de8b
commit
459e35f261
10
flow/Arena.h
10
flow/Arena.h
|
@ -662,7 +662,15 @@ struct Traceable<Standalone<T>> : std::conditional<Traceable<T>::value, std::tru
|
|||
static std::string toString(const Standalone<T>& value) { return Traceable<T>::toString(value); }
|
||||
};
|
||||
|
||||
#define LiteralStringRef(str) StringRef((const uint8_t*)(str), sizeof((str)) - 1)
|
||||
namespace literal_string_ref {
|
||||
template <class T, int Size>
|
||||
StringRef LiteralStringRefHelper(const char* str) {
|
||||
static_assert(std::is_same_v<T, const char(&)[Size]>, "Argument to LiteralStringRef must be a literal string");
|
||||
return StringRef(reinterpret_cast<const uint8_t*>(str), Size);
|
||||
}
|
||||
} // namespace literal_string_ref
|
||||
#define LiteralStringRef(str) literal_string_ref::LiteralStringRefHelper<decltype(str), sizeof(str)>(str)
|
||||
|
||||
inline StringRef operator"" _sr(const char* str, size_t size) {
|
||||
return StringRef(reinterpret_cast<const uint8_t*>(str), size);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue