function template
<iterator>

std::operator- (move_iterator)

template <class Iterator1, class Iterator2>  auto operator- (const move_iterator<Iterator>& lhs,                  const move_iterator<Iterator>& rhs)  -> decltype (rhs.base()-lhs.base()) { return rhs.base()-lhs.base(); }
Subtraction operator
Returns the distance between lhs and rhs.

The function returns the same as subtracting the base iterators of lhs and rhs.

This operator is also overloaded as a member function to return a move iterator offset by -n element positions (see move_iterator::operator-).

Parameters

lhs, rhs
move_iterator objects (to the left- and right-hand side of the operator, respectively) for whose base iterators the subtraction operation is defined.

Return value

The number of elements between lhs and rhs.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// subtracting move_iterators
#include <iostream>     // std::cout
#include <iterator>     // std::move_iterator
#include <string>       // std::string

int main () {
  std::string foo[] = {"one","two","three"};

  std::move_iterator<std::string*> from (foo);
  std::move_iterator<std::string*> until (foo);
  until += sizeof(foo)/sizeof(std::string);

  std::cout << "foo has " << (until-from) << " elements.\n";

  return 0;
}

Output:

foo has 3 elements


Data races

Both objects, lhs and rhs, are accessed.

Exception safety

Provides the same level of guarantee as the same operation applied on the base iterators of lhs and rhs.

See also