std::experimental::basic_string_view<CharT,Traits>:: basic_string_view
From cppreference.net
<
cpp
|
experimental
|
basic string view
|
constexpr
basic_string_view
(
)
noexcept
;
|
(1) | (库基础技术规范) |
|
constexpr
basic_string_view
(
const
basic_string_view
&
other
)
noexcept
=
default
;
|
(2) | (库基础技术规范) |
|
template
<
class
Allocator
>
basic_string_view ( const std:: basic_string < CharT, Traits, Allocator > & str ) noexcept ; |
(3) | (库基础技术规范) |
|
constexpr
basic_string_view
(
const
CharT
*
s, size_type count
)
;
|
(4) | (库基础技术规范) |
|
constexpr
basic_string_view
(
const
CharT
*
s
)
;
|
(5) | (库基础技术规范) |
1)
默认构造函数。构造一个空的
basic_string_view
。
2)
拷贝构造函数。构造一个与
other
内容相同的视图。
3)
构造一个字符数组视图,该数组起始于
str.
data
(
)
所指向的元素,包含前
str.
size
(
)
个字符。
4)
构造一个指向以
s
所指向元素开头的字符数组前
count
个字符的视图。
s
可以包含空字符。如果
[
s
,
s
+
count
)
不是有效范围(即使构造函数可能不会访问该范围内的任何元素),则行为未定义。
5)
构造一个指向以空字符结尾的字符串
s
的视图,不包含终止空字符。视图长度通过
Traits
::
length
(
s
)
确定。如果
[
s
,
s
+
Traits
::
length
(
s
)
)
不是有效范围(即使构造函数可能不会访问该范围内的任何元素),则行为未定义。
目录 |
参数
| other | - | 用于初始化视图的另一个视图 |
| str | - | 用于初始化视图的 C++ 字符串对象 |
| s | - | 指向字符数组或 C 字符串的指针,用于初始化视图 |
| count | - | 视图中包含的字符数量 |
异常
4,5)
不抛出任何异常。
复杂度
1-4)
常量。
5)
与
s
的长度呈线性关系。
示例
运行此代码
#include <experimental/string_view> #include <iostream> int main() { std::string cppstr = "Foo"; char array[3] = {'B', 'a', 'r'}; std::experimental::string_view cppstr_v(cppstr); std::experimental::string_view array_v(array, sizeof array); std::experimental::wstring_view wcstr_v = L"xyzzy"; std::cout << cppstr_v << '\n' << array_v << '\n' << wcstr_v.size() << '\n'; }
输出:
Foo Bar 5
参见
|
赋值视图
(公开成员函数) |