On 14 January 2016 at 11:45, Gottlob Frege
On Wed, Jan 13, 2016 at 1:56 PM, Nevin Liber
wrote: On 13 January 2016 at 12:25, Lee Clagett
wrote: The macro `STRING_VIEW` seems unnecessary because the `string_view` constructor taking a single NULL-terminated string is also `constexpr`.
While the templated constructor for basic_string_view is constexpr, this constructor for string_view cannot be used in a constexpr context because char_traits<char>::length isn't constexpr. :-( See LWG 2232 http://cplusplus.github.io/LWG/lwg-active.html#2232.
I've been told it works this way by design...
So yes, we do need the macro.
Can it be a constexpr function that returns an initializer list? Or something, anything,... I hate macros :-(
You should be able to write a constexpr length() function, then a constexpr factory function which will return a string_view (calling the same constructor that the macro does). It just won't use strlen() in non-constexpr contexts, but we probably don't care for this use case. -- Nevin ":-)" Liber mailto:nevin@eviloverlord.com +1-847-691-1404