Modifying operations
The call stringView.swap(stringView2)
swaps the content of the two string views. The methods remove_prefix
and remove_suffix
are unique to a string view because a string supports neither. remove_prefix
shrinks its start forward; remove_suffix
shrinks its end backwards.
// string_view.cpp
...
#include
<string_view>
...
using
namespace
std
;
string
str
=
" A lot of space"
;
string_view
strView
=
str
;
strView
.
remove_prefix
(
min
(
strView
.
find_first_not_of
(
" "
),
strView
.
size
()));
cout
<<
str
<<
endl
// " A lot of space
<<
strView
<<
endl
;
// "A lot of space"
char
arr
[]
=
{
'A'
,
' '
,
'l'
,
'o'
,
't'
,
' '
,
'o'
,
'f'
,
' '
,
's'
,
'p'
,
'a'
,
'c'
,
'e'
,
'\0'
,
'\0'
,
'\0'
};
string_view
strView2
(
arr
,
sizeof...