New paper: N3762, string_view: a non-owning reference to a string, revision 5 -- Jeffrey Yasskin

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 from const char* and std::string. It provides the const member operations from std::string to ease conversion. This paper follows Chromium and Bloomberg in extending string_view to basic_string_view<charT>, and further extends it to include a traits parameter to match basic_string. We provide typedefs to parallel the 4 basic_string typedefs.

Both Google's and LLVM's string_view types (but not Bloomberg's) extend the interface from std::string to provide some helpful utility functions:

Versions of std::string operations that take string_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.

Comments (0)

There are currently no comments on this entry.