A RetroSearch Logo

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

Search Query:

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

function template

<iterator>

std::operator- (reverse_iterator)
template <class Iterator>  typename reverse_iterator<Iterator>::difference_type operator- (    const reverse_iterator<Iterator>& lhs,    const reverse_iterator<Iterator>& rhs);
template <class Iterator1, class Iterator2>  auto operator- (const reverse_iterator<Iterator>& lhs,                  const reverse_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 lhs's base iterator from rhs's base iterator.



Parameters
lhs, rhs
reverse_iterator

objects (to the left- and right-hand side of the operator, respectively), having both the same template parameter (

Iterator

).


reverse_iterator

objectss (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
17
18
// operator- on reverse_iterator
#include <iostream>     // std::cout
#include <iterator>     // std::reverse_iterator
#include <vector>       // std::vector

int main () {
  std::vector<int> myvector;
  for (int i=0; i<10; i++) myvector.push_back(i);

  std::reverse_iterator<std::vector<int>::iterator> from,until;

  from = myvector.rbegin();
  until = myvector.rend();

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

  return 0;
}

Output:
myvector has 10 elements.


Data races Both objects, lhs and rhs, are accessed.

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

See also
operator+ (reverse_iterator)
Addition operator (function template)
reverse_iterator::operator-
Subtraction operator (public member function)
reverse_iterator::operator-=
Retrocede 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