标准库头文件(C++17)

2025-10-22 09:25:37

C++

编译器支持

自由(freestanding)与宿主(hosted)

语言

标准库

标准库头文件

具名要求

特性测试宏 (C++20)

语言支持库

概念库 (C++20)

诊断库

内存管理库

元编程库 (C++11)

通用工具库

容器库

迭代器库

范围库 (C++20)

算法库

字符串库

文本处理库

数值库

日期和时间库

输入/输出库

文件系统库 (C++17)

并发支持库 (C++11)

执行控制库 (C++26)

技术规范

符号索引

外部库

[编辑] 标准库头文件

语言支持

(C++20)

(C++26)

(C++20)

(C++11)

(C++11)

(C++20)

(C++23)

(C++20)

概念

(C++20)

诊断

(C++26)

(C++23)

(C++11)

内存管理

(C++17)

(C++11)

元编程

(C++11)

(C++11)

通用工具

(C++17)

(C++20)

(C++17)

(C++23)

(C++20)

(C++17)

(C++11)

(C++11)

(C++17)

容器

(C++11)

(C++23)

(C++23)

(C++11)

(C++26)

(C++26)

(C++23)

(C++20)

(C++11)

(C++11)

迭代器

Ranges

(C++23)

(C++20)

算法

字符串

(C++11)

(C++17)

文本处理

(C++11/17/26*)

(C++11)

(C++26)

数值

(C++11)

(C++26)

(C++20)

(C++11)

(C++26)

时间

(C++11)

C 兼容性

(C++11/17/20*)

(直到 C++20)

(C++11/17/20*)

(C++11/17/20*)

(C++11/17/20*)

输入/输出

(C++11)

(C++17)

(C++23)

(C++23)

(C++98/26*)

(C++20)

并发支持

(C++11)

(C++20)

(C++11)

(C++11)

(C++26)

(C++20)

(C++11)

(C++26)

(C++20)

(C++14)

(C++23)

(C++20)

(C++11)

执行支持

(C++17)

[编辑]

此头文件是 字符串 库的一部分。

目录

1 包含

2 类

2.1 前向声明

3 函数

3.1 范围访问

3.2 字面量

4 概要

4.1 类模板 std::basic_string_view

包含

(C++20)

三路比较运算符 支持[编辑]

basic_string_view(C++17)

只读字符串视图 (类模板) [编辑]

std::string_view (C++17)

std::basic_string_view

std::u8string_view (C++20)

std::basic_string_view

std::u16string_view (C++17)

std::basic_string_view

std::u32string_view (C++17)

std::basic_string_view

std::wstring_view (C++17)

std::basic_string_view

std::hashstd::hashstd::hashstd::hashstd::hash(C++17)(C++17)(C++20)(C++17)(C++17)

字符串视图的哈希支持 (类模板特化) [编辑]

前向声明

定义于头文件

hash(C++11)

哈希函数对象 (类模板) [编辑]

函数

operator==operator!=operatoroperator<=operator>=operator<=>(C++17)(在 C++20 中移除)(在 C++20 中移除)(在 C++20 中移除)(在 C++20 中移除)(在 C++20 中移除)(C++20)

按字典序比较两个 string_view (函数模板) [编辑]

operator<<(C++17)

对 string_view 执行流输出 (函数模板) [编辑]

swap

交换两个对象的值 (函数模板) [编辑]

范围访问

begincbegin(C++11)(C++14)

返回指向容器或数组开头的迭代器 (函数模板) [编辑]

endcend(C++11)(C++14)

返回指向容器或数组末尾的迭代器 (函数模板) [编辑]

rbegincrbegin(C++14)

返回指向容器或数组开头的反向迭代器 (函数模板) [编辑]

rendcrend(C++14)

返回容器或数组的反向结束迭代器 (函数模板) [编辑]

sizessize(C++17)(C++20)

返回容器或数组的大小 (函数模板) [编辑]

empty(C++17)

检查容器是否为空 (函数模板) [编辑]

data(C++17)

获取指向底层数组的指针 (函数模板) [编辑]

字面量

在内联命名空间 std::literals::string_view_literals 中定义

operator""sv(C++17)

创建字符数组字面量的字符串视图 (函数) [编辑]

[编辑] 概要

#include

namespace std {

// class template basic_string_view

template>

class basic_string_view;

template

inline constexpr bool ranges::enable_view> = true;

template

inline constexpr bool ranges::enable_borrowed_range> =

true;

// non-member comparison functions

template

constexpr bool operator==(basic_string_view x,

basic_string_view y) noexcept;

template

constexpr /* see description */

operator<=>(basic_string_view x,

basic_string_view y) noexcept;

// sufficient additional overloads of comparison functions

// inserters and extractors

template

basic_ostream&

operator<<(basic_ostream& os,

basic_string_view str);

// basic_string_view typedef names

using string_view = basic_string_view;

using u8string_view = basic_string_view;

using u16string_view = basic_string_view;

using u32string_view = basic_string_view;

using wstring_view = basic_string_view;

// hash support

template struct hash;

template<> struct hash;

template<> struct hash;

template<> struct hash;

template<> struct hash;

template<> struct hash;

inline namespace literals {

inline namespace string_view_literals {

// suffix for basic_string_view literals

constexpr string_view operator""sv(const char* str, size_t len) noexcept;

constexpr u8string_view operator""sv(const char8_t* str, size_t len) noexcept;

constexpr u16string_view operator""sv(const char16_t* str, size_t len) noexcept;

constexpr u32string_view operator""sv(const char32_t* str, size_t len) noexcept;

constexpr wstring_view operator""sv(const wchar_t* str, size_t len) noexcept;

}

}

}

[编辑] 类模板 std::basic_string_view

namespace std {

template>

class basic_string_view {

public:

// types

using Traits_type = Traits;

using value_type = CharT;

using pointer = value_type*;

using const_pointer = const value_type*;

using reference = value_type&;

using const_reference = const value_type&;

using const_iterator = /* implementation-defined */

using iterator = const_iterator;

using const_reverse_iterator = reverse_iterator;

using reverse_iterator = const_reverse_iterator;

using size_type = size_t;

using difference_type = ptrdiff_t;

static constexpr size_type npos = size_type(-1);

// construction and assignment

constexpr basic_string_view() noexcept;

constexpr basic_string_view(const basic_string_view&) noexcept = default;

constexpr basic_string_view& operator=(const basic_string_view&) noexcept = default;

constexpr basic_string_view(const CharT* str);

constexpr basic_string_view(nullptr_t) = delete;

constexpr basic_string_view(const CharT* str, size_type len);

template

constexpr basic_string_view(It begin, End end);

template

constexpr explicit basic_string_view(R&& r);

// iterator support

constexpr const_iterator begin() const noexcept;

constexpr const_iterator end() const noexcept;

constexpr const_iterator cbegin() const noexcept;

constexpr const_iterator cend() const noexcept;

constexpr const_reverse_iterator rbegin() const noexcept;

constexpr const_reverse_iterator rend() const noexcept;

constexpr const_reverse_iterator crbegin() const noexcept;

constexpr const_reverse_iterator crend() const noexcept;

// capacity

constexpr size_type size() const noexcept;

constexpr size_type length() const noexcept;

constexpr size_type max_size() const noexcept;

constexpr bool empty() const noexcept;

// element access

constexpr const_reference operator[](size_type pos) const;

constexpr const_reference at(size_type pos) const;

constexpr const_reference front() const;

constexpr const_reference back() const;

constexpr const_pointer data() const noexcept;

// modifiers

constexpr void remove_prefix(size_type n);

constexpr void remove_suffix(size_type n);

constexpr void swap(basic_string_view& s) noexcept;

// string operations

constexpr size_type copy(CharT* s, size_type n, size_type pos = 0) const;

constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;

constexpr int compare(basic_string_view s) const noexcept;

constexpr int compare(size_type pos1, size_type n1, basic_string_view s) const;

constexpr int compare(size_type pos1, size_type n1, basic_string_view s,

size_type pos2, size_type n2) const;

constexpr int compare(const CharT* s) const;

constexpr int compare(size_type pos1, size_type n1, const CharT* s) const;

constexpr int compare(size_type pos1, size_type n1, const CharT* s,

size_type n2) const;

constexpr bool starts_with(basic_string_view x) const noexcept;

constexpr bool starts_with(CharT x) const noexcept;

constexpr bool starts_with(const CharT* x) const;

constexpr bool ends_with(basic_string_view x) const noexcept;

constexpr bool ends_with(CharT x) const noexcept;

constexpr bool ends_with(const CharT* x) const;

constexpr bool contains(basic_string_view x) const noexcept;

constexpr bool contains(CharT x) const noexcept;

constexpr bool contains(const CharT* x) const;

// searching

constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept;

constexpr size_type find(CharT c, size_type pos = 0) const noexcept;

constexpr size_type find(const CharT* s, size_type pos, size_type n) const;

constexpr size_type find(const CharT* s, size_type pos = 0) const;

constexpr size_type rfind(basic_string_view s, size_type pos = npos) const noexcept;

constexpr size_type rfind(CharT c, size_type pos = npos) const noexcept;

constexpr size_type rfind(const CharT* s, size_type pos, size_type n) const;

constexpr size_type rfind(const CharT* s, size_type pos = npos) const;

constexpr size_type find_first_of(basic_string_view s,

size_type pos = 0) const noexcept;

constexpr size_type find_first_of(CharT c, size_type pos = 0) const noexcept;

constexpr size_type find_first_of(const CharT* s, size_type pos, size_type n) const;

constexpr size_type find_first_of(const CharT* s, size_type pos = 0) const;

constexpr size_type find_last_of(basic_string_view s,

size_type pos = npos) const noexcept;

constexpr size_type find_last_of(CharT c, size_type pos = npos) const noexcept;

constexpr size_type find_last_of(const CharT* s, size_type pos, size_type n) const;

constexpr size_type find_last_of(const CharT* s, size_type pos = npos) const;

constexpr size_type find_first_not_of(basic_string_view s,

size_type pos = 0) const noexcept;

constexpr size_type find_first_not_of(CharT c, size_type pos = 0) const noexcept;

constexpr size_type find_first_not_of(const CharT* s, size_type pos,

size_type n) const;

constexpr size_type find_first_not_of(const CharT* s, size_type pos = 0) const;

constexpr size_type find_last_not_of(basic_string_view s,

size_type pos = npos) const noexcept;

constexpr size_type find_last_not_of(CharT c, size_type pos = npos) const noexcept;

constexpr size_type find_last_not_of(const CharT* s, size_type pos,

size_type n) const;

constexpr size_type find_last_not_of(const CharT* s, size_type pos = npos) const;

private:

const_pointer data_; // exposition only

size_type size_; // exposition only

};

// deduction guides

template

basic_string_view(It, End) -> basic_string_view>;

template

basic_string_view(R&&) -> basic_string_view>;

}

Copyright © 2022 世界杯奖杯_男足世界杯预选赛 - cbatop.com All Rights Reserved.