Iterators

xiaoxiao2021-03-06  85

Iterators

1.NPUT ITERATORS must meet the following conditions: 1) prefix and postfix 2) Operator! = 3) Dereference * and only support read, not support write4) Operator == See in msdntemplate Find (.... ) Indicates that the Find algorithm requires the input item. see below: template InputIterator find (InputIterator first, InputIterator last, const T & value) {while (first = last && * first = value!!) { first;} return first;}

2.Output Iterators must meet the following criteria: 1) perfix and postfix 2) dereference *, only support writesee below: template OutputIterator copy (InputIterator first, InputIterator last, OutputIterator result) {while (first ! = last) {* result = * first; first; result;} Return Result;

3.Forward Iterators meet all requirements of Input and Ouput Iterator, while you can store a Forward Intelate and use it to traverse, so you can use it.

MultiPass Algorithm. See Below: Template Void Replace

4. Bidirectional Iterators meets all the requirements of Forward Iterator, while providing prefix - and postfix - list :: iterator meets the requirements, due to List is a Double Link Listsuch Algorithm Reverse Require Bidirectional Iterators

5.random Access Iterators meets all the requirements of the Bidirectional Iterator, and provides the following operations (R, S is Random Access Iterator, N integers): 1) R N and R-N2) R [N], ie * (R n) 3) Two-way jump, R = N and R- = N4) Operator- with random access itrator, ie RS, get an integer value 5) Operator Comparisons Between Random Access Iterator, ie R S, R <= S, R> = S, get a BOOL value vector, Deque's Iterator satisfies these requirements. Such an algorithm requires iterator has binary_search, sort, etc. 6.Insert Iterator1) back_insert_iterator push_back member function using 2) front_insert_iterator push_front member function using 3) insert_iterator insert member function when using copy, if not give As a result, you need to use a sufficient space, you need to use Insert Iterator. Such as copy (vec.begin (), vec.end (), back_insert_iterator > (vec2)); standard provides another simplification: Template Inline Back_INSERT_ITERATOR Back_Inserter (Container & X) {RETURN BACK_INSERT_ITERATOR (x);}, Copy can be simplified to copy (vec.begin (), vec.end (), back_inserter (vec2)); use Insert Iterator, when assigning, 即 = value This will be converted to: contain.push_back (value); IT always points to the container pass-the-End Pointer, and Operator is always not dry.

Since the vector does not provide push_front, Front_Insert_Iiterator cannot use the Vector, and all containers provide INSERT operations.

For, INSERT_ITEARTOR can be used by all containers.

7.Istream_iterator and ostream_iterator uses the ITERATOR and OUTPUT ITERATOR, just two associated objects must be input (ISTREAM &) and output

Ostream &)

转载请注明原文地址:https://www.9cbs.com/read-106907.html

New Post(0)