Megjegyzés
Az oldalhoz való hozzáféréshez engedély szükséges. Megpróbálhat bejelentkezni vagy módosítani a címtárat.
Az oldalhoz való hozzáféréshez engedély szükséges. Megpróbálhatja módosítani a címtárat.
Az checked_array_iterator osztály lehetővé teszi, hogy egy tömböt vagy mutatót ellenőrzött iterátorsá alakítsa át. Ezt az osztályt burkolóként (a make_checked_array_iterator függvénnyel) használhatja nyers mutatókhoz vagy tömbökhöz, hogy a figyelmeztetések globális elijesítése helyett az ellenőrzés és a nem ellenőrzött mutató figyelmeztetések kezelése érdekében célzott módon szolgáljon. Szükség esetén használhatja az osztály nem ellenőrzött verzióját, unchecked_array_iterator.
Bankjegy
Az checked_array_iterator osztály el lett távolítva az MSVC Build Tools 14.51-ben.
Ez az osztály a C++ standard kódtár Microsoft bővítménye. A függvény használatával implementált kód nem hordozható olyan C++ Standard buildkörnyezetekbe, amelyek nem támogatják ezt a Microsoft bővítményt. Az osztály használatát nem igénylő kód írását bemutató példáért tekintse meg az alábbi második példát.
Syntax
template <class _Iterator>
class checked_array_iterator;
Remarks
Ez az osztály az stdext névtérben van definiálva.
A bejelölt iterátor funkcióval kapcsolatos további információkért és példakódért lásd: Ellenőrzött iterátorok.
Examples
Az alábbi minta bemutatja, hogyan definiálhat és használhat egy ellenőrzött tömb iterátort.
Ha a cél nem elég nagy ahhoz, hogy az összes másolt elemet megtartsa, például a sor módosítása esetén ez a helyzet:
copy(a, a + 5, checked_array_iterator<int*>(b, 5));
to
copy(a, a + 5, checked_array_iterator<int*>(b, 4));
Futásidejű hiba történik.
// compile with: /EHsc /W4 /MTd
#include <algorithm>
#include <iostream>
using namespace std;
using namespace stdext;
int main() {
int a[]={0, 1, 2, 3, 4};
int b[5];
copy(a, a + 5, checked_array_iterator<int*>(b, 5));
cout << "(";
for (int i = 0 ; i < 5 ; i++)
cout << " " << b[i];
cout << " )" << endl;
// constructor example
checked_array_iterator<int*> checked_out_iter(b, 5);
copy(a, a + 5, checked_out_iter);
cout << "(";
for (int i = 0 ; i < 5 ; i++)
cout << " " << b[i];
cout << " )" << endl;
}
/* Output:
( 0 1 2 3 4 )
( 0 1 2 3 4 )
*/
Annak érdekében, hogy ne legyen szükség az checked_array_iterator osztályra C++ standard kódtár-algoritmusok használatakor, fontolja meg a vector dinamikusan lefoglalt tömbök helyett a használatát. Az alábbi példa bemutatja, hogyan teheti ezt meg.
// compile with: /EHsc /W4 /MTd
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
std::vector<int> v(10);
int *arr = new int[10];
for (int i = 0; i < 10; ++i)
{
v[i] = i;
arr[i] = i;
}
// std::copy(v.begin(), v.end(), arr); will result in
// warning C4996. To avoid this warning while using int *,
// use the Microsoft extension checked_array_iterator.
std::copy(v.begin(), v.end(),
stdext::checked_array_iterator<int *>(arr, 10));
// Instead of using stdext::checked_array_iterator and int *,
// consider using std::vector to encapsulate the array. This will
// result in no warnings, and the code will be portable.
std::vector<int> arr2(10); // Similar to int *arr = new int[10];
std::copy(v.begin(), v.end(), arr2.begin());
for (int j = 0; j < arr2.size(); ++j)
{
cout << " " << arr2[j];
}
cout << endl;
return 0;
}
/* Output:
0 1 2 3 4 5 6 7 8 9
*/
Constructors
| Constructor | Leírás |
|---|---|
| checked_array_iterator | Létrehoz egy alapértelmezett checked_array_iterator vagy egy checked_array_iterator mögöttes iterátort. |
Typedefs
| Típus neve | Leírás |
|---|---|
| difference_type | Olyan típus, amely két, ugyanazon tárolón belüli elemekre hivatkozó elem közötti checked_array_iteratorkülönbséget biztosítja. |
| Mutató | Olyan típus, amely mutatót ad egy adott elem által kezelt elemhez checked_array_iterator. |
| reference | Olyan típus, amely egy checked_array_iterator. |
Tagfüggvények
| Tagfüggvény | Leírás |
|---|---|
| alap | Helyreállítja a mögöttes iterátort a sajátjából checked_array_iterator. |
Operators
| Operator | Leírás |
|---|---|
| operátor== | Két checked_array_iterators-t tesztel az egyenlőség érdekében. |
| operator!= | Két checked_array_iterators-t tesztel az egyenlőtlenségre. |
| operátor< | Ellenőrzi, hogy az checked_array_iterator operátor bal oldalán kisebb-e, mint a checked_array_iterator jobb oldalon. |
| operátor> | Ellenőrzi, hogy az checked_array_iterator operátor bal oldalán nagyobb-e, mint a checked_array_iterator jobb oldalon. |
| operátor<= | Ellenőrzi, hogy az checked_array_iterator operátor bal oldalán kisebb vagy egyenlő-e, mint a checked_array_iterator jobb oldalon. |
| operátor>= | Ellenőrzi, hogy az checked_array_iterator operátor bal oldalán nagyobb vagy egyenlő-e a checked_array_iterator jobb oldalon lévő értéknél. |
| operátor* | Egy cím elemét checked_array_iterator adja vissza. |
| operátor-> | Egy mutatót ad checked_array_iteratorvissza a . |
| operátor++ | A következő elemre növeli a checked_array_iterator elemet. |
| operátor-- | Az előző elemre vonatkozó decrements checked_array_iterator . |
| operator+= | Megadott eltolást ad hozzá egy checked_array_iterator. |
| operator+ | Eltolást ad hozzá egy iterátorhoz, és visszaadja a checked_array_iterator beszúrt elemet az új eltolási pozícióban. |
| operátor-= | Egy megadott eltolás decresítése egy checked_array_iterator. |
| Üzemeltető- | Egy iterátor eltolásának eltolása, és visszaadja a checked_array_iterator beszúrt elemet az új eltolási pozícióba. |
operator[] |
Egy adott számú pozíció által checked_array_iterator kezelt elem eltolására mutató hivatkozást ad vissza. |
Requirements
Fejléc:<iterátor>
Névtér: stdext
checked_array_iterator::base
Helyreállítja a mögöttes iterátort a sajátjából checked_array_iterator.
_Iterator base() const;
Remarks
További információ: Ellenőrzött iterátorok.
Example
// checked_array_iterators_base.cpp
// compile with: /EHsc
#include <iterator>
#include <vector>
#include <iostream>
int main() {
using namespace std;
int V1[10];
for (int i = 0; i < 10 ; i++)
V1[i] = i;
int* bpos;
stdext::checked_array_iterator<int*> rpos(V1, 10);
rpos++;
bpos = rpos.base ( );
cout << "The iterator underlying rpos is bpos & it points to: "
<< *bpos << "." << endl;
}
/* Output:
The iterator underlying rpos is bpos & it points to: 1.
*/
checked_array_iterator::checked_array_iterator
Létrehoz egy alapértelmezett checked_array_iterator vagy egy checked_array _iterator mögöttes iterátort.
checked_array_iterator();
checked_array_iterator(
ITerator ptr,
size_t size,
size_t index = 0);
Parameters
ptr
Mutató a tömbhöz.
méret
A tömb mérete.
index
(Nem kötelező) A tömb egyik eleme az iterátor inicializálásához. Alapértelmezés szerint az iterátor a tömb első elemére van inicializálva.
Remarks
További információ: Ellenőrzött iterátorok.
Example
// checked_array_iterators_ctor.cpp
// compile with: /EHsc
#include <iterator>
#include <iostream>
using namespace std;
using namespace stdext;
int main() {
int a[] = {0, 1, 2, 3, 4};
int b[5];
copy(a, a + 5, checked_array_iterator<int*>(b,5));
for (int i = 0 ; i < 5 ; i++)
cout << b[i] << " ";
cout << endl;
checked_array_iterator<int*> checked_output_iterator(b,5);
copy (a, a + 5, checked_output_iterator);
for (int i = 0 ; i < 5 ; i++)
cout << b[i] << " ";
cout << endl;
checked_array_iterator<int*> checked_output_iterator2(b,5,3);
cout << *checked_output_iterator2 << endl;
}
/* Output:
0 1 2 3 4
0 1 2 3 4
3
*/
checked_array_iterator::d ifference_type
Olyan típus, amely két, ugyanazon tárolón belüli elemekre hivatkozó elem közötti checked_array_iteratorkülönbséget biztosítja.
typedef typename iterator_traits<_Iterator>::difference_type difference_type;
Remarks
A checked_array_iterator különbség típusa megegyezik az iterátor különbségtípusával.
A kódminta checked_array_iterator::operátor[] című témakörben talál.
További információ: Ellenőrzött iterátorok.
checked_array_iterator::operator==
Két checked_array_iterators-t tesztel az egyenlőség érdekében.
bool operator==(const checked_array_iterator<_Iterator>& right) const;
Parameters
jobb
Az checked_array_iterator , hogy melyik ellen kell ellenőrizni az egyenlőséget.
Remarks
További információ: Ellenőrzött iterátorok.
Example
// checked_array_iterators_opeq.cpp
// compile with: /EHsc
#include <iterator>
#include <iostream>
using namespace std;
using namespace stdext;
int main() {
int a[] = {0, 1, 2, 3, 4};
int b[5];
copy(a, a + 5, checked_array_iterator<int*>(b,5));
copy(a, a + 5, checked_array_iterator<int*>(b,5));
checked_array_iterator<int*> checked_output_iterator(b,5);
checked_array_iterator<int*> checked_output_iterator2(b,5);
if (checked_output_iterator2 == checked_output_iterator)
cout << "checked_array_iterators are equal" << endl;
else
cout << "checked_array_iterators are not equal" << endl;
copy (a, a + 5, checked_output_iterator);
checked_output_iterator++;
if (checked_output_iterator2 == checked_output_iterator)
cout << "checked_array_iterators are equal" << endl;
else
cout << "checked_array_iterators are not equal" << endl;
}
/* Output:
checked_array_iterators are equal
checked_array_iterators are not equal
*/
checked_array_iterator::operátor!=
Két checked_array_iterators-t tesztel az egyenlőtlenségre.
bool operator!=(const checked_array_iterator<_Iterator>& right) const;
Parameters
jobb
Az checked_array_iterator , hogy melyik ellen kell ellenőrizni az egyenlőtlenséget.
Remarks
További információ: Ellenőrzött iterátorok.
Example
// checked_array_iterators_opneq.cpp
// compile with: /EHsc
#include <iterator>
#include <iostream>
using namespace std;
using namespace stdext;
int main() {
int a[] = {0, 1, 2, 3, 4};
int b[5];
copy(a, a + 5, checked_array_iterator<int*>(b,5));
copy(a, a + 5, checked_array_iterator<int*>(b,5));
checked_array_iterator<int*> checked_output_iterator(b,5);
checked_array_iterator<int*> checked_output_iterator2(b,5);
if (checked_output_iterator2 != checked_output_iterator)
cout << "checked_array_iterators are not equal" << endl;
else
cout << "checked_array_iterators are equal" << endl;
copy (a, a + 5, checked_output_iterator);
checked_output_iterator++;
if (checked_output_iterator2 != checked_output_iterator)
cout << "checked_array_iterators are not equal" << endl;
else
cout << "checked_array_iterators are equal" << endl;
}
/* Output:
checked_array_iterators are equal
checked_array_iterators are not equal
*/
checked_array_iterator::operator<
Ellenőrzi, hogy az checked_array_iterator operátor bal oldalán kisebb-e, mint a checked_array_iterator jobb oldalon.
bool operator<(const checked_array_iterator<_Iterator>& right) const;
Parameters
jobb
Az checked_array_iterator , hogy melyik ellen kell ellenőrizni az egyenlőtlenséget.
Remarks
További információ: Ellenőrzött iterátorok.
Example
// checked_array_iterators_oplt.cpp
// compile with: /EHsc
#include <iterator>
#include <iostream>
using namespace std;
using namespace stdext;
int main() {
int a[] = {0, 1, 2, 3, 4};
int b[5];
copy(a, a + 5, checked_array_iterator<int*>(b,5));
copy(a, a + 5, checked_array_iterator<int*>(b,5));
checked_array_iterator<int*> checked_output_iterator(b,5);
checked_array_iterator<int*> checked_output_iterator2(b,5);
if (checked_output_iterator2 < checked_output_iterator)
cout << "checked_output_iterator2 is less than checked_output_iterator" << endl;
else
cout << "checked_output_iterator2 is not less than checked_output_iterator" << endl;
copy (a, a + 5, checked_output_iterator);
checked_output_iterator++;
if (checked_output_iterator2 < checked_output_iterator)
cout << "checked_output_iterator2 is less than checked_output_iterator" << endl;
else
cout << "checked_output_iterator2 is not less than checked_output_iterator" << endl;
}
/* Output:
checked_output_iterator2 is not less than checked_output_iterator
checked_output_iterator2 is less than checked_output_iterator
*/
checked_array_iterator::operator>
Ellenőrzi, hogy az checked_array_iterator operátor bal oldalán nagyobb-e, mint a checked_array_iterator jobb oldalon.
bool operator>(const checked_array_iterator<_Iterator>& right) const;
Parameters
jobb
Az checked_array_iterator összehasonlításhoz.
Remarks
Tekintse meg checked_array_iterator::operator< a kódmintát.
További információ: Ellenőrzött iterátorok.
checked_array_iterator::operator<=
Ellenőrzi, hogy az checked_array_iterator operátor bal oldalán kisebb vagy egyenlő-e, mint a checked_array_iterator jobb oldalon.
bool operator<=(const checked_array_iterator<_Iterator>& right) const;
Parameters
jobb
Az checked_array_iterator összehasonlításhoz.
Remarks
Tekintse meg checked_array_iterator::operator>= a kódmintát.
További információ: Ellenőrzött iterátorok.
checked_array_iterator::operator>=
Ellenőrzi, hogy az checked_array_iterator operátor bal oldalán nagyobb vagy egyenlő-e a checked_array_iterator jobb oldalon lévő értéknél.
bool operator>=(const checked_array_iterator<_Iterator>& right) const;
Parameters
jobb
Az checked_array_iterator összehasonlításhoz.
Remarks
További információ: Ellenőrzött iterátorok.
Example
// checked_array_iterators_opgteq.cpp
// compile with: /EHsc
#include <iterator>
#include <iostream>
using namespace std;
using namespace stdext;
int main() {
int a[] = {0, 1, 2, 3, 4};
int b[5];
copy(a, a + 5, checked_array_iterator<int*>(b,5));
copy(a, a + 5, checked_array_iterator<int*>(b,5));
checked_array_iterator<int*> checked_output_iterator(b,5);
checked_array_iterator<int*> checked_output_iterator2(b,5);
if (checked_output_iterator2 >= checked_output_iterator)
cout << "checked_output_iterator2 is greater than or equal to checked_output_iterator" << endl;
else
cout << "checked_output_iterator2 is less than checked_output_iterator" << endl;
copy (a, a + 5, checked_output_iterator);
checked_output_iterator++;
if (checked_output_iterator2 >= checked_output_iterator)
cout << "checked_output_iterator2 is greater than or equal to checked_output_iterator" << endl;
else
cout << "checked_output_iterator2 is less than checked_output_iterator" << endl;
}
/* Output:
checked_output_iterator2 is greater than or equal to checked_output_iterator
checked_output_iterator2 is less than checked_output_iterator
*/
checked_array_iterator::operátor*
Egy cím elemét checked_array_iterator adja vissza.
reference operator*() const;
Visszaadott érték
A . által checked_array_iteratorkezelt elem értéke.
Remarks
További információ: Ellenőrzött iterátorok.
Example
// checked_array_iterator_pointer.cpp
// compile with: /EHsc
#include <iterator>
#include <algorithm>
#include <vector>
#include <utility>
#include <iostream>
using namespace std;
using namespace stdext;
int main() {
int a[] = {0, 1, 2, 3, 4};
int b[5];
pair<int, int> c[1];
copy(a, a + 5, checked_array_iterator<int*>(b,5));
for (int i = 0 ; i < 5 ; i++)
cout << b[i] << endl;
c[0].first = 10;
c[0].second = 20;
checked_array_iterator<int*> checked_output_iterator(b,5);
checked_array_iterator<int*>::pointer p = &(*checked_output_iterator);
checked_array_iterator<pair<int, int>*> chk_c(c, 1);
checked_array_iterator<pair<int, int>*>::pointer p_c = &(*chk_c);
cout << "b[0] = " << *p << endl;
cout << "c[0].first = " << p_c->first << endl;
}
/* Output:
0
1
2
3
4
b[0] = 0
c[0].first = 10
*/
checked_array_iterator::operator->
Egy mutatót ad checked_array_iteratorvissza a .
pointer operator->() const;
Visszaadott érték
Az elem által megcímzett elem mutatója checked_array_iterator.
Remarks
A kódmintához lásd: checked_array_iterator::p ointer .
További információ: Ellenőrzött iterátorok.
checked_array_iterator::operátor++
A következő elemre növeli a checked_array_iterator elemet.
checked_array_iterator& operator++();
checked_array_iterator<_Iterator> operator++(int);
Visszaadott érték
Az első operátor visszaadja az előtagot checked_array_iterator , a második pedig a postincrement operátor a növekmény egy példányát checked_array_iterator.
Remarks
További információ: Ellenőrzött iterátorok.
Example
// checked_array_iterators_op_plus_plus.cpp
// compile with: /EHsc
#include <vector>
#include <iostream>
int main() {
using namespace stdext;
using namespace std;
int a[] = {6, 3, 77, 199, 222};
int b[5];
copy(a, a + 5, checked_array_iterator<int*>(b,5));
checked_array_iterator<int*> checked_output_iterator(b,5);
cout << *checked_output_iterator << endl;
++checked_output_iterator;
cout << *checked_output_iterator << endl;
checked_output_iterator++;
cout << *checked_output_iterator << endl;
}
/* Output:
6
3
77
*/
checked_array_iterator::operátor-
Az előző elemre vonatkozó decrements checked_array_iterator .
checked_array_iterator<_Iterator>& operator--();
checked_array_iterator<_Iterator> operator--(int);
Visszaadott érték
Az első operátor az előre megadott checked_array_iterator értéket adja vissza, a második pedig a postdecrement operátort, amely a dekrementált egy példányát checked_array_iteratoradja vissza.
Remarks
További információ: Ellenőrzött iterátorok.
Example
// checked_array_iterators_op_minus_minus.cpp
// compile with: /EHsc
#include <vector>
#include <iostream>
int main() {
using namespace stdext;
using namespace std;
int a[] = {6, 3, 77, 199, 222};
int b[5];
copy(a, a + 5, checked_array_iterator<int*>(b,5));
checked_array_iterator<int*> checked_output_iterator(b,5);
cout << *checked_output_iterator << endl;
checked_output_iterator++;
cout << *checked_output_iterator << endl;
checked_output_iterator--;
cout << *checked_output_iterator << endl;
}
/* Output:
6
3
6
*/
checked_array_iterator::operátor+=
Megadott eltolást ad hozzá egy checked_array_iterator.
checked_array_iterator<_Iterator>& operator+=(difference_type _Off);
Parameters
_Off
Az eltolás, amellyel növelhető az iterátor.
Visszaadott érték
Hivatkozás a checked_array_iterator.
Remarks
További információ: Ellenőrzött iterátorok.
Example
// checked_array_iterators_op_plus_eq.cpp
// compile with: /EHsc
#include <vector>
#include <iostream>
int main() {
using namespace stdext;
using namespace std;
int a[] = {6, 3, 77, 199, 222};
int b[5];
copy(a, a + 5, checked_array_iterator<int*>(b,5));
checked_array_iterator<int*> checked_output_iterator(b,5);
cout << *checked_output_iterator << endl;
checked_output_iterator += 3;
cout << *checked_output_iterator << endl;
}
/* Output:
6
199
*/
checked_array_iterator::operátor+
Eltolást ad hozzá egy iterátorhoz, és visszaadja a checked_array_iterator beszúrt elemet az új eltolási pozícióban.
checked_array_iterator<_Iterator> operator+(difference_type _Off) const;
Parameters
_Off
A hozzáadandó eltolás.checked_array_iterator
Visszaadott érték
Az checked_array_iterator eltolási elem kezelése.
Remarks
További információ: Ellenőrzött iterátorok.
Example
// checked_array_iterators_op_plus.cpp
// compile with: /EHsc
#include <vector>
#include <iostream>
int main() {
using namespace stdext;
using namespace std;
int a[] = {6, 3, 77, 199, 222};
int b[5];
copy(a, a + 5, checked_array_iterator<int*>(b,5));
checked_array_iterator<int*> checked_output_iterator(b,5);
cout << *checked_output_iterator << endl;
checked_output_iterator = checked_output_iterator + 3;
cout << *checked_output_iterator << endl;
}
/* Output:
6
199
*/
checked_array_iterator::operator-=
Egy megadott eltolás decresítése egy checked_array_iterator.
checked_array_iterator<_Iterator>& operator-=(difference_type _Off);
Parameters
_Off
Az eltolás, amellyel növelhető az iterátor.
Visszaadott érték
Hivatkozás a checked_array_iterator.
Remarks
További információ: Ellenőrzött iterátorok.
Example
// checked_array_iterators_op_minus_eq.cpp
// compile with: /EHsc
#include <vector>
#include <iostream>
int main() {
using namespace stdext;
using namespace std;
int a[] = {6, 3, 77, 199, 222};
int b[5];
copy(a, a + 5, checked_array_iterator<int*>(b,5));
checked_array_iterator<int*> checked_output_iterator(b,5);
checked_output_iterator += 3;
cout << *checked_output_iterator << endl;
checked_output_iterator -= 2;
cout << *checked_output_iterator << endl;
}
/* Output:
199
3
*/
checked_array_iterator::operátor-
Egy iterátor eltolásának eltolása, és visszaadja a checked_array_iterator beszúrt elemet az új eltolási pozícióba.
checked_array_iterator<_Iterator> operator-(difference_type _Off) const;
difference_type operator-(const checked_array_iterator& right) const;
Parameters
_Off
A dekrementelendő eltolás a checked_array_iterator.
Visszaadott érték
Az checked_array_iterator eltolási elem kezelése.
Remarks
További információ: Ellenőrzött iterátorok.
checked_array_iterator::operátor[]
Egy adott számú pozíció által checked_array_iterator kezelt elem eltolására mutató hivatkozást ad vissza.
reference operator[](difference_type _Off) const;
Parameters
_Off
A cím eltolása checked_array_iterator .
Visszaadott érték
Az elemeltolásra mutató hivatkozás.
Remarks
További információ: Ellenőrzött iterátorok.
Example
// checked_array_iterators_op_diff.cpp
// compile with: /EHsc
#include <vector>
#include <iostream>
int main() {
using namespace std;
int V1[10];
for (int i = 0; i < 10 ; i++)
V1[i] = i;
// Declare a difference type for a parameter
stdext::checked_array_iterator<int*>::difference_type diff = 2;
stdext::checked_array_iterator<int*> VChkIter(V1, 10);
stdext::checked_array_iterator<int*>::reference refrpos = VChkIter [diff];
cout << refrpos + 1 << endl;
}
/* Output:
3
*/
checked_array_iterator::p ointer
Olyan típus, amely mutatót ad egy adott elem által kezelt elemhez checked_array_iterator.
typedef typename iterator_traits<_Iterator>::pointer pointer;
Remarks
A kódmintát a checked_array_iterator::operátor* című témakörben talál.
További információ: Ellenőrzött iterátorok.
checked_array_iterator::referencia
Olyan típus, amely egy checked_array_iterator.
typedef typename iterator_traits<_Iterator>::reference reference;
Remarks
A kódminta checked_array_iterator::operátor[] című témakörben talál.
További információ: Ellenőrzött iterátorok.