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_view
is implicitly constructible fromconst char*
andstd::string
. It provides theconst
member operations fromstd::string
to ease conversion. This paper follows Chromium and Bloomberg in extendingstring_view
tobasic_string_view<charT>
, and further extends it to include a traits parameter to matchbasic_string
. We provide typedefs to parallel the 4basic_string
typedefs.Both Google's and LLVM's
string_view
types (but not Bloomberg's) extend the interface fromstd::string
to provide some helpful utility functions:
starts_with
ends_with
remove_prefix
remove_suffix
split
trim
consume_prefix
count
Versions of
std::string
operations that takestring_view
instead 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.