src: Add specialization for char to avoid reinterpret_cast in constexpr
This commit is contained in:
parent
3db9c2c796
commit
863a944179
|
@ -401,8 +401,9 @@ public:
|
||||||
explicit StringRef(const ImmutableString &s)
|
explicit StringRef(const ImmutableString &s)
|
||||||
: base(s.c_str()), len(s.size()) {}
|
: base(s.c_str()), len(s.size()) {}
|
||||||
explicit StringRef(const char *s) : base(s), len(strlen(s)) {}
|
explicit StringRef(const char *s) : base(s), len(strlen(s)) {}
|
||||||
|
constexpr StringRef(const char *s, size_t n) : base(s), len(n) {}
|
||||||
template <typename CharT>
|
template <typename CharT>
|
||||||
constexpr StringRef(const CharT *s, size_t n)
|
StringRef(const CharT *s, size_t n)
|
||||||
: base(reinterpret_cast<const char *>(s)), len(n) {}
|
: base(reinterpret_cast<const char *>(s)), len(n) {}
|
||||||
template <typename InputIt>
|
template <typename InputIt>
|
||||||
StringRef(InputIt first, InputIt last)
|
StringRef(InputIt first, InputIt last)
|
||||||
|
@ -413,7 +414,7 @@ public:
|
||||||
len(std::distance(first, last)) {}
|
len(std::distance(first, last)) {}
|
||||||
template <typename CharT, size_t N>
|
template <typename CharT, size_t N>
|
||||||
constexpr static StringRef from_lit(const CharT(&s)[N]) {
|
constexpr static StringRef from_lit(const CharT(&s)[N]) {
|
||||||
return StringRef(s, N - 1);
|
return StringRef{s, N - 1};
|
||||||
}
|
}
|
||||||
static StringRef from_maybe_nullptr(const char *s) {
|
static StringRef from_maybe_nullptr(const char *s) {
|
||||||
if (s == nullptr) {
|
if (s == nullptr) {
|
||||||
|
|
Loading…
Reference in New Issue