Vector operators
提供:cppreference.com
Syntax:
#include <vector> T& operator[]( size_type index ); const T& operator[]( size_type index ) const; vector& operator=(const vector& c2); bool operator==(const vector& c1, const vector& c2); bool operator!=(const vector& c1, const vector& c2); bool operator<(const vector& c1, const vector& c2); bool operator>(const vector& c1, const vector& c2); bool operator<=(const vector& c1, const vector& c2); bool operator>=(const vector& c1, const vector& c2);
全てのC++コンテナは基本的な演算子(==, !=, %%<=%%, >=, <, >, = )を用いて比較、割り付けをすることができる。 ベクタのそれぞれの要素は[]演算子で検査することができる。
ほかのベクタとの比較や割り付けは 線形時間かかります。
[]演算子は 定数時間かかります。
以下の場合、2つのベクタは等しい:
- 2つのサイズが等しい
- それぞれのベクタの位置iの要素が等しい
ベクタ間の比較は辞書順に行われる。
例えば、次のコードではベクタの要素へのアクセスに[]演算子を使っている。
vector<int> v( 5, 1 ); for( int i = 0; i < v.size(); i++ ) { cout << "Element " << i << " is " << v[i] << endl; }
Related Topics: at