1. Table of Contents
2. Changelog
2.1. R0
-
Initial revision
3. Motivation and Scope
Thestd :: string (and std :: string_view ) api has a lot of nice features and utility functions, but can be improved even further.
Currently, to get the first N characters of a string, we need to do std :: string :: substr ( 0 , N ) . This is fine, but people might be confused as to the usage of the 0 in the function call.
Similarly, to get the last N characters of a string, we need to do std :: string :: substr ( size () - N , N ) . This is also fine, but again, the first parameter could lead to confusion, or even a possible error if the wrong number were passed.
To facilitate these simple operations, I suggest adding and (and similar counterparts to ).
Having these 2 utility functions brings a couple of benefits:
-
It is more obvious and clear what the programmer intent is,
conveys better meaning as opposed to. first ( N ) , same for. substr ( 0 , N ) and. last ( N ) . substr ( size () - N , N ) -
Since there are less arguments, and the argument is only a count, there is less potential for programmer error
-
It is generally simpler and less typing.