From 863a9441798b001001bade04cee6d5d311491d13 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 12 Mar 2016 17:29:07 +0900 Subject: [PATCH] src: Add specialization for char to avoid reinterpret_cast in constexpr --- src/template.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/template.h b/src/template.h index b15efa02..1664714a 100644 --- a/src/template.h +++ b/src/template.h @@ -401,8 +401,9 @@ public: explicit StringRef(const ImmutableString &s) : base(s.c_str()), len(s.size()) {} explicit StringRef(const char *s) : base(s), len(strlen(s)) {} + constexpr StringRef(const char *s, size_t n) : base(s), len(n) {} template - constexpr StringRef(const CharT *s, size_t n) + StringRef(const CharT *s, size_t n) : base(reinterpret_cast(s)), len(n) {} template StringRef(InputIt first, InputIt last) @@ -413,7 +414,7 @@ public: len(std::distance(first, last)) {} template 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) { if (s == nullptr) {