Namespaces
Variants

std:: vector<bool, Alloc>:: reference

From cppreference.net
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 を介して行われるベクターへの読み取りまたは書き込みは、基盤となるベクター全体に対して読み取りまたは書き込みを行う可能性があります。

目次

メンバー関数

(constructor)
参照を構築する
(public member function)
(destructor)
参照を破棄する
(public member function)
operator=
参照先のビットに値を代入する
(public member function)
operator bool
参照先のビットを返す
(public member function)
flip
参照先のビットを反転する
(public member function)

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 ( ) ;
(constexpr since C++20)

参照を破棄します。

std::vector<bool, Alloc>::reference:: operator=

reference & operator = ( bool x ) ;
(1) (C++11以降 noexcept)
(C++20以降 constexpr)
constexpr const reference & operator = ( bool x ) const noexcept ;
(2) (C++23以降)
reference & operator = ( const reference & x ) ;
(3) (C++11以降 noexcept)
(C++20以降 constexpr)

参照先のビットに値を代入します。

const修飾された operator = は、 std::vector<bool,Alloc>::iterator output_iterator 要件を満たすことを可能にします。

(C++23以降)

パラメータ

x - 代入する値

戻り値

* this

std::vector<bool, Alloc>::reference:: operator bool

operator bool ( ) const ;
(noexcept since C++11)
(constexpr since C++20)

参照されているビットの値を返します。

戻り値

参照されているビット。

std::vector<bool, Alloc>::reference:: flip

void flip ( ) ;
(C++11以降 noexcept)
(C++20以降 constexpr)

参照されているビットを反転します。

ヘルパークラス

std:: formatter <std::vector<bool, Alloc>::reference>

template < class T, class CharT >

requires /*is-vector-bool-reference*/ < T >

struct formatter < T, CharT > ;
(C++23以降)

std::vector < bool , Alloc > :: reference に対する std::formatter の特殊化。この特殊化は、参照されるビットが bool に変換されてフォーマットされる際に、基盤となるフォーマッタ( underlying_ と表記)として std:: formatter < bool , CharT > を使用する。

説明専用の定数 /*is-vector-bool-reference*/ < T > は、 T が何らかの型 Alloc に対する型 std::vector < bool , Alloc > :: reference を表し、かつ std::vector < bool , Alloc > プログラム定義の特殊化 でない場合に限り true となる。

メンバ関数

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> の公開メンバー関数)
[static]
二つの std::vector<bool>:: reference s を交換
(公開静的メンバー関数)

外部リンク

Scott Meyers著「Effective Modern C++」(2015年)、第2章、項目6: " auto が望ましくない型を推論する場合は明示的に型指定された初期化子イディオムを使用する" (p.43-46) — プロキシクラス std::vector<bool>::reference の誤用の可能性について説明している。