名前空間
変種
操作

std::move_iterator<Iter>::operator[]

From cppreference.com
 
 
イテレータライブラリ
イテレータのコンセプト
イテレータのプリミティブ
アルゴリズムのコンセプトとユーティリティ
間接呼び出し可能コンセプト
共通アルゴリズム要件
(C++20)
(C++20)
(C++20)
ユーティリティ
(C++20)
イテレータアダプタ
Rangeアクセス
(C++11)(C++14)
(C++14)(C++14)  
(C++11)(C++14)
(C++14)(C++14)  
(C++17)(C++20)
(C++17)
(C++17)
 
 
/* 未指定 */ operator[]( difference_type n ) const;
(C++17 以降 constexpr)
(C++20まで)
constexpr reference operator[]( difference_type n ) const;
(C++20以降)

指定された相対位置にある要素への参照を返します。

目次

[編集] パラメータ

n - 現在の位置からの相対位置

[編集] 戻り値

std::move(current [n])(C++20 まで)ranges::iter_move(current + n)(C++20 以降)

[編集] ノート

戻り値の型は未指定です。これは、基になるイテレータの `operator[]` の戻り値の型も未指定であるためです(LegacyRandomAccessIterator を参照)。

(C++20まで)

[編集]

#include <cstddef>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <string>
#include <vector>
 
void print(auto rem, const auto& v)
{
    for (std::cout << rem; const auto& e : v)
        std::cout << std::quoted(e) << ' ';
    std::cout << '\n';
}
 
int main()
{
    std::vector<std::string> p{"alpha", "beta", "gamma", "delta"}, q;
    print("1) p: ", p);
 
    std::move_iterator it{p.begin()};
 
    for (std::size_t t{}; t != p.size(); ++t)
        q.emplace_back(it[t]); 
 
    print("2) p: ", p);
    print("3) q: ", q);
 
    std::list l{1, 2, 3};
    std::move_iterator it2{l.begin()};
//  it2[1] = 13; // Compilation error: the underlying iterator
                 // does not model the random access iterator
//  *it2 = 999;  // Compilation error: using rvalue as lvalue
}

実行結果の例

1) p: "alpha" "beta" "gamma" "delta"
2) p: "" "" "" ""
3) q: "alpha" "beta" "gamma" "delta"

[編集] 関連項目

指し示す要素にアクセスする
(public member function) [編集]
English 日本語 中文(简体) 中文(繁體)