A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/iterator/move_iterator/operator_minus-free/ below:

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:


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
operator+ (move_iterator)
Addition operator (function template)
move_iterator::operator-
Subtraction operator (public member function)
move_iterator::operator-=
Decrease iterator (public member function)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4