Doc. no.: P0903R2 Date: 2018-05-07 Reply to: Ashley Hedberg (
[email protected]), Titus Winters (
[email protected]), Jorg Brown (
[email protected]) Audience: LEWG/EWG/LWG Define basic_string_view(nullptr) Abstract 1 Background 2 What is a string_view? 2 What does const char* mean? 2 What is an empty string_view? 3 Existing behavior of basic_string_view(null_char_ptr) 3 Motivation 4 Once we convert into the string_view domain, code is better 4 Nul-terminated strings are not the design we'd choose today 5 Nul-termination + null can match string_view’s existing design 5 Discussion Points 6 Can we we weaken preconditions? (Or: do we believe that string_view(null_char_ptr) is more likely to match programmer intent or to represent a bug?) 6 How many functions are there today that accept const char* and (by contract or not) allow for null values? 7 Which view of string_view design speaks to you: is it a lightweight string, or is it a pointer-and-length pair, or is it a mix of the two? 7 Which provides more net value to the C++ community? 7 Could we add a new type such as nullable_string_view? 7 Will the proposed changes negatively affect performance? 8 Proposed Wording 8 Change History 9 Acknowledgements 9 Abstract This paper proposes modifying the requirements of basic_string_view(const charT* str) such that it becomes well-defined for null pointers, both at compile-time and at runtime. Background What is a string_view? The string_view type has shipped in C++17. Substantive redesign is likely out of the question without getting into P0684 territory and long-term refactoring plans.