名前空間
変種
操作

std::input_iterator_tag, std::output_iterator_tag, std::forward_iterator_tag, std::bidirectional_iterator_tag, std::random_access_iterator_tag

提供: cppreference.com
< cpp‎ | iterator

 
 
イテレータライブラリ
イテレータプリミティブ
Original:
Iterator primitives
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
iterator_traits
input_iterator_tag
output_iterator_tag
forward_iterator_tag
bidirectional_iterator_tag
random_access_iterator_tag
iterator
イテレータアダプタ
Original:
Iterator adaptors
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
reverse_iterator
ストリーム反復子
Original:
Stream iterators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
istream_iterator
ostream_iterator
istreambuf_iterator
ostreambuf_iterator
イテレータ操作
Original:
Iterator operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
advance
distance
prev(C++11)
next(C++11)
アクセスの範囲
Original:
Range access
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
begin(C++11)
end(C++11)
 
Defined in header <iterator>
struct input_iterator_tag { };
struct output_iterator_tag { };
struct forward_iterator_tag : public input_iterator_tag { };
struct bidirectional_iterator_tag : public forward_iterator_tag { };
struct random_access_iterator_tag : public bidirectional_iterator_tag { };
空の型std::input_iterator_tagstd::output_iterator_tagforward_iterator_tagbidirectional_iterator_tag、とrandom_access_iterator_tagイテレータのカテゴリに基づいて適切なアルゴリズムを選択するために使用されます。すべてのイテレータ型の場合は、typedefstd::iterator_traits<Iterator>::iterator_categoryは、これらの5つのタグ·タイプのいずれかに別名である、利用可能です.
Original:
The empty types std::input_iterator_tag, std::output_iterator_tag, forward_iterator_tag, bidirectional_iterator_tag, and random_access_iterator_tag are used to select appropriate algorithms based on the category of an iterator. For every iterator type, a typedef std::iterator_traits<Iterator>::iterator_category is available, which is an alias to one of these five tag types.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集]

イテレータカテゴリタグに基づいたアルゴリズムを選択するための一般的な手法は、(代替はstd :: enable_ifです)ディスパッチャ·ファンクションを使用することです
Original:
Common technique for algorithm selection based on iterator category tags is to use a dispatcher function (the alternative is std::enable_if)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <iostream>
#include <vector>
#include <list>
#include <iterator>
 
template< class BDIter >
void alg(BDIter, BDIter, std::bidirectional_iterator_tag)
{
    std::cout << "alg() called for bidirectional iterator\n";
}
 
template <class RAIter>
void alg(RAIter, RAIter, std::random_access_iterator_tag)
{
    std::cout << "alg() called for random-access iterator\n";
}
 
template< class Iter >
void alg(Iter first, Iter last)
{
    alg(first, last,
        typename std::iterator_traits<Iter>::iterator_category());
}
 
int main()
{
    std::vector<int> v;
    alg(v.begin(), v.end());
 
    std::list<int> l;
    alg(l.begin(), l.end());
 
//    std::istreambuf_iterator<char> i1(std::cin), i2;
//    alg(i1, i2); // compile error: no matching function for call
}

Output:

alg() called for random-access iterator
alg() called for bidirectional iterator

[編集] も参照してください

基本的なイテレータ
Original:
the basic iterator
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(クラステンプレート) [edit]
イテレータのプロパティに統一されたインタフェースを提供します
Original:
provides uniform interface to the properties of an iterator
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(クラステンプレート) [edit]