#include #include #include #include using namespace std; template void f(ITERATOR first, ITERATOR last) { typename iterator_traits::value_type x = *first; cout << x << " is a copy of the value to which first refers.\n"; typename iterator_traits::pointer p = &*first; cout << "first refers to the value " << *p << " at address " << static_cast(p) << ".\n"; typename iterator_traits::reference r = *first; cout << "first refers to the value " << r << " at address " << static_cast(&r) << ".\n"; typename iterator_traits::difference_type d = 0; for (; first != last; ++first) { ++d; } cout << "The iterators refer to elements that are " << d << " elements apart.\n\n"; } int main() { int a[] = {10, 20, 30, 40, 50}; const size_t n = sizeof a / sizeof a[0]; cout << fixed; int *it1 = a; int *it2 = a + n - 1; f(it1, it2); vector v(a, a + n); vector::iterator it3 = v.begin(); f(it3, it3 + 3); return EXIT_SUCCESS; }