From 7a84dff0b2bd7d3fb9f72bbde2a6a60029bac88e Mon Sep 17 00:00:00 2001 From: Nadav Har'El Date: Mon, 29 Dec 2014 17:12:21 +0200 Subject: [PATCH] sstring: constructor from C string The constructor from "const char_type *" wouldn't really work when char_type != char, because strlen() won't work on such pointers. It is more convenient to have a constructor from an ordinary const char * (e.g., a C string literal), and solve the type problem with an ugly cast. This only makes sense when sizeof(char_type)==1 (i.e., it is char, unsigned char, or signed char), but I think we make this assumption in other places as well (e.g., in determining the size we need to allocate). Signed-off-by: Nadav Har'El --- core/sstring.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/sstring.hh b/core/sstring.hh index a63a1ef1c1..f586699eb2 100644 --- a/core/sstring.hh +++ b/core/sstring.hh @@ -105,7 +105,7 @@ public: u.external.str[size] = '\0'; } } - basic_sstring(const char_type* x) : basic_sstring(x, std::strlen(x)) {} + basic_sstring(const char* x) : basic_sstring(reinterpret_cast(x), std::strlen(x)) {} basic_sstring(std::basic_string& x) : basic_sstring(x.c_str(), x.size()) {} basic_sstring(std::initializer_list x) : basic_sstring(x.begin(), x.end() - x.begin()) {} basic_sstring(const char_type* b, const char_type* e) : basic_sstring(b, e - b) {}