Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) std::distance

 

std::distance is an STL algorithm to determine the distance (in number of elements) between two iterators.

 

#include <cassert>
#include <vector>

int main()
{
  std::vector<int> v;
  assert(std::distance(v.begin(),v.end())==0);
  v.push_back(0);
  v.push_back(1);
  v.push_back(2);
  v.push_back(3);
  v.push_back(4);
  assert(std::distance(v.begin(),v.end())==5);
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict