std::vector<bool, Alloc>::reference
來自 cppreference.com
< cpp | 容器 | vector bool
class reference; |
||
std::vector
<bool, Alloc> 特化定義了 std::vector
<bool, Alloc>::reference 作為一個可公開訪問的巢狀類。std::vector
<bool, Alloc>::reference 代理了 std::vector
<bool, Alloc> 中單個位的引用的行為。
std::vector
<bool, Alloc>::reference 的主要用途是提供一個可從 operator[] 返回的左值。
透過 std::vector
<bool, Alloc>::reference 對向量進行的任何讀取或寫入都可能讀取或寫入整個底層向量。
[編輯] 成員函式
(建構函式) |
構造引用 (公開成員函式) |
(解構函式) |
銷燬引用 (公開成員函式) |
operator= |
將值賦給被引用的位 (公開成員函式) |
operator bool |
返回被引用的位 (public member function) |
flip |
翻轉被引用的位 (公開成員函式) |
std::vector<bool, Alloc>::reference::reference
reference( const reference& ) = default; |
(C++11 起) (C++20 起為 constexpr) |
|
從另一個引用構造引用。 複製建構函式被隱式宣告。(直到 C++11)
其他建構函式只能由 std::vector
<bool, Alloc> 訪問。
std::vector<bool, Alloc>::reference::~reference
~reference(); |
(C++20 起為 constexpr) | |
銷燬引用。
std::vector<bool, Alloc>::reference::operator=
reference& operator=( bool x ); |
(1) | (C++11 起無異常丟擲) (C++20 起為 constexpr) |
constexpr const reference& operator=( bool x ) const noexcept; |
(2) | (C++23 起) |
reference& operator=( const reference& x ); |
(3) | (C++11 起無異常丟擲) (C++20 起為 constexpr) |
將值賦給被引用的位。
引數
x | - | 要賦的值 |
返回值
*this
std::vector<bool, Alloc>::reference::operator bool
operator bool() const; |
(C++11 起無異常丟擲) (C++20 起為 constexpr) |
|
返回被引用的位的值。
返回值
被引用的位。
std::vector<bool, Alloc>::reference::flip
void flip(); |
(C++11 起無異常丟擲) (C++20 起為 constexpr) |
|
反轉被引用的位。
[編輯] 輔助類
std::formatter<std::vector<bool, Alloc>::reference>
template< class T, class CharT > requires /*is-vector-bool-reference*/<T> |
(C++23 起) | |
特化 std::formatter 用於 std::vector
<bool, Alloc>::reference。該特化使用 std::formatter<bool, CharT> 作為其底層格式化器(表示為 underlying_
),其中被引用的位被轉換為 bool 以進行格式化。
僅用於說明的常量 /*is-vector-bool-reference*/<T> 為 true 當且僅當 T
表示型別 std::vector
<bool, Alloc>::reference 且 Alloc
是某種型別,並且 std::vector
<bool, Alloc> 不是程式定義的特化。
成員函式
template< class ParseContext > constexpr ParseContext::iterator parse( ParseContext& ctx ); |
(1) | (C++23 起) |
template< class FormatContext > FormatContext::iterator format( const T& r, FormatContext& ctx ) const; |
(2) | (C++23 起) |
1) 等價於 return
underlying_
.parse(ctx);。2) 等價於 return
underlying_
.format(r, ctx);。[編輯] 示例
本節不完整 原因:無示例 |
[編輯] 參閱
訪問指定的元素 ( std::vector<T,Allocator> 的公共成員函式) | |
[靜態] |
交換兩個 std::vector<bool>:: references(公共靜態成員函式) |
[編輯] 外部連結
Scott Meyers (2015) 著《Effective Modern C++》,第 2 章,第 6 條:“當 auto 推匯出不期望的型別時,使用顯式型別初始化表示式慣用法。”(第 43-46 頁)——描述了代理類 std::vector<bool>::reference 可能的誤用。 |