
On Mon, Nov 19, 2012 at 4:49 PM, Olaf van der Spek <ml@vdspek.org> wrote:
On Mon, Nov 19, 2012 at 4:42 AM, Yanchenko Maxim <maximyanchenko@yandex.ru> wrote:
Mathias, it's not just compile-time size (which is good to have as well, btw). What about literals with a zero character inside, like "foo\0bar"?
What about them? Such literals aren't proper null-terminated strings, are they?
I believe string_ref should be able to handle the case, in order to be useful.
For such literals the (const char*, size_t) constructor should be used.
This is simply not practical: // code duplication string_ref lit("Hello, World!", sizeof("Hello, World!")); wstring_ref lit(L"Hello, World!", sizeof(L"Hello, World!") / sizeof(wchar_t)); // error prone string_ref lit("Hello, World!", 13); Although I don't aim to address the \0 in the middle of the string literal, I'd like such construction to be cleaner and preferably without strlen/wcslen: string_ref lit = string_ref::from_literal("Hello, World!"); or string_ref lit = make_literal_ref("Hello, World!"); or whatever. Not every compiler is able to optimize away strlen/wcslen on a literal, this generator is intended to remove its need altogether. PS: I don't really understand why we are arguing about this little helper anyway. There are people who will find it useful, others can safely ignore it.