Previous fileTop of DocumentContentsIndex pageNext file
Apache C++ Standard Library Reference Guide

distance()

Library:  Iterators


Function

Local Index

No Entries

Summary

A function that computes the distance between two iterators

Synopsis

#include <iterator>

namespace std {
  template <class ForwardIterator>
  iterator_traits<ForwardIterator>::difference_type
  distance(ForwardIterator start,
           ForwardIterator finish);

  template <class ForwardIterator, class Distance>
  void distance(ForwardIterator start,
                ForwardIterator finish,
                Distance& n);
}

Description

The distance() function template computes the distance between two iterators. The first version returns that value, while the second version increments n by that value. The last iterator must be reachable from the first iterator.

Note that the second version of this function is obsolete. It is included for backward compatibility and to accommodate compilers that do not support partial specialization. The first version of the function is not available with compilers that do not support partial specialization, since it depends on iterator_traits, which itself depends on that particular language feature.

Example

Warnings

If your compiler does not support partial specialization, you can't use the version of distance() that returns the distance. Instead, you must use the version that increments a reference parameter.

See Also

Sequences, Random Access Iterators

Standards Conformance

ISO/IEC 14882:1998 -- International Standard for Information Systems -- Programming Language C++, Section 24.3.4



Previous fileTop of DocumentContentsIndex pageNext file