random_access_iterator_tag Struct

반환 형식에 대해 제공 하는 클래스 iterator_category 임의 액세스 반복기를 나타내는 함수입니다.

struct random_access_iterator_tag
   : public bidirectional_iterator_tag {};

설명

범주 태그 클래스 선택 알고리즘에 대 한 태그를 컴파일할 때 사용 됩니다.템플릿 함수는 컴파일 타임에 가장 효율적인 알고리즘을 사용할 수 있도록 구체적인 범주 인수 반복기를 찾아야 합니다.모든 반복기의 형식에 대 한 Iterator, iterator_traits<Iterator>:: iterator_category 반복기의 동작에 설명 하는 구체적인 범주 태그 수를 정의 합니다.

동일한 형식인 반복기<반복 계산>:: iterator_category반복 계산 는 임의 액세스 반복기로 처는 개체에 설명 합니다.

예제

// iterator_rait.cpp
// compile with: /EHsc
#include <iterator>
#include <vector>
#include <iostream>
#include <list>

using namespace std;

int main( )
{
   vector<int> vi;
   vector<char> vc;
   list<char> lc;
   iterator_traits<vector<int>:: iterator>::iterator_category cati;
   iterator_traits<vector<char>:: iterator>::iterator_category catc;
   iterator_traits<list<char>:: iterator>::iterator_category catlc;

   // These are both random-access iterators
   cout << "The type of iterator for vector<int> is "
       << "identified by the tag:\n " 
       << typeid ( cati ).name( ) << endl;
   cout << "The type of iterator for vector<char> is "
       << "identified by the tag:\n " 
       << typeid ( catc ).name( ) << endl;
   if ( typeid ( cati ) == typeid( catc ) )
      cout << "The iterators are the same." << endl << endl;
   else
      cout << "The iterators are not the same." << endl << endl;

   // But the list iterator is bidirectinal, not random access
   cout << "The type of iterator for list<char> is "
       << "identified by the tag:\n " 
       << typeid (catlc).name( ) << endl;

   // cout << ( typeid ( vi.begin( ) ) == typeid( vc.begin( ) ) ) << endl;
   if ( typeid ( vi.begin( ) ) == typeid( vc.begin( ) ) )
      cout << "The iterators are the same." << endl;
   else
      cout << "The iterators are not the same." << endl;
   // A random-access iterator is a bidirectional iterator.
   cout << ( void* ) dynamic_cast< iterator_traits<list<char>:: iterator>
          ::iterator_category* > ( &catc ) << endl;
}

샘플 출력

다음 출력에 대 한 x 86입니다.

The type of iterator for vector<int> is identified by the tag:
 struct std::random_access_iterator_tag
The type of iterator for vector<char> is identified by the tag:
 struct std::random_access_iterator_tag
The iterators are the same.

The type of iterator for list<char> is identified by the tag:
 struct std::bidirectional_iterator_tag
The iterators are not the same.
0012FF3B

요구 사항

헤더: <iterator>

네임 스페이스: std

참고 항목

참조

bidirectional_iterator_tag Struct

표준 C++ 라이브러리에서 스레드로부터의 안전성

표준 템플릿 라이브러리