|
Standard Template Library Programmer's GuideComplexity Constant time if InputIterator is a model of random access iterator, otherwise linear time. Example int main() { list<int> L; L.push_back(0); L.push_back(1); assert(distance(L.begin(), L.end()) == L.size()); } Notes [1] This is the reason that distance is not defined for output iterators: it is impossible to compare two output iterators for equality. [2] Forgetting to initialize n to 0 is a common mistake. [3] The new distance interface uses the iterator_traits class, which relies on a C++ feature known as partial specialization. Many of today's compilers don't implement the complete standard; in particular, many compilers do not support partial specialization. If your compiler does not support partial specialization, then you will not be able to use the newer version of distance, or any other STL components that involve iterator_traits. See also distance_type, advance, Input iterator, Random access iterator, Iterator tags, iterator_traits, Iterator overview. advance Categories: algorithms, iterators Component type: function Prototype template <class InputIterator, class Distance> void advance(InputIterator& i, Distance n); Description Advance(i, n) increments the iterator i by the distance n ...» | Код для вставки книги в блог HTML
phpBB
текст
|
|