New paper: N3594, std::join: An Algorithm for Joining a Range of Elements -- Greg Miller
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: N3594
Date: 2013-03-13
std::join: An Algorithm for Joining a Range of Elements
by Greg Miller
Excerpt:
Creating a string by joining the elements in a collection with a separator between each element is a common task in many applications. Often the elements themselves are strings, so joining them is fairly straight forward. However, it is not uncommon to join collections of types other than string. For example, one might want to log a collection of
int
identifiers with each value separated by a comma and a space. In this case there needs to be some way to format the collection's element type as a string.The
std::join()
API described in this paper describes a function that is easy to use in all the common cases, such as joining strings and string-like objects as well as primitives likeint
,float
, etc. This API is also extensible through a Formatter function object and is able to join arbitrary types.Joining strings is the inverse of splitting strings and they are often thought of together. This proposal describes a joining function to go along with the
std::split()
function described in N3593 (std::split
).This proposal depends on or refers to the following proposals:
- N3593 (
std::split
)- N3609 (
s
)td::string_view
- N3513 (Range support)