namespace std {
template<class Iterator1, class Iterator2>
typename reverse_iterator<Iterator>::difference_type
operator-(const reverse_iterator<Iterator1>& x,
const reverse_iterator<Iterator2>& y); // C++03
template <class Iterator1, class Iterator2>
auto operator-(const reverse_iterator<Iterator1>& x,
const reverse_iterator<Iterator2>& y)
-> decltype(y.current - x.current); // C++11
template <class Iterator1, class Iterator2>
constexpr auto operator-(const reverse_iterator<Iterator1>& x,
const reverse_iterator<Iterator2>& y)
-> decltype(y.current - x.current); // C++17
}
概要
2つのreverse_iterator
の差を求める
戻り値
y.current - x.current
例
#include <iostream>
#include <vector>
#include <iterator>
int main()
{
std::vector<int> v = {1, 2, 3};
std::reverse_iterator<decltype(v)::iterator> it1(v.end());
std::reverse_iterator<decltype(v)::iterator> it2(v.begin());
std::ptrdiff_t result = it2 - it1;
std::cout << result << std::endl;
}
出力
3