函式模板
<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(); }
減法運算子
返回 lhsrhs 之間的距離

該函式返回的結果與減去 lhsrhsbase iterators 的結果相同。

此運算子也過載為成員函式,用於返回一個偏移 n 個元素位置的move iterator(參見move_iterator::operator-)。

引數

lhs, rhs
用於減法運算子左右兩邊的move_iterator物件,它們支援減法運算。

返回值

lhsrhs 之間的元素數量。

示例

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;
}

輸出

foo has 3 elements


資料競爭

訪問 lhsrhs 兩個物件。

異常安全

提供與應用於 lhsrhsbase iterators 相同的保證級別。

另見