A new WG21 paper is available. A copy is linked below, and the paper will also appear in the next normal WG21 mailing. If you are not a committee member, please use the comments section below or the std-proposals forum for public discussion.
Document number: N3762
Date: 2013-09-01
string_view: a non-owning reference to a string, revision 5
by Jeffrey Yasskin
Excerpt:
References to strings are very common in C++ programs, but often the callee doesn't care about the exact type of the object that owns the data. ...
Google, LLVM, and Bloomberg have independently implemented a string-reference type to encapsulate this kind of argument.
string_viewis implicitly constructible fromconst char*andstd::string. It provides theconstmember operations fromstd::stringto ease conversion. This paper follows Chromium and Bloomberg in extendingstring_viewtobasic_string_view<charT>, and further extends it to include a traits parameter to matchbasic_string. We provide typedefs to parallel the 4basic_stringtypedefs.Both Google's and LLVM's
string_viewtypes (but not Bloomberg's) extend the interface fromstd::stringto provide some helpful utility functions:
starts_withends_withremove_prefixremove_suffixsplittrimconsume_prefixcountVersions of
std::stringoperations that takestring_viewinstead also give the standard a way to provide in-place operations on non-null-terminated byte/character sequences:
- hash, as requested by c++std-lib-31935
- In a future addition, numeric conversions

Add a Comment
Comments are closed.