- iterator[meta header]
- std[meta namespace]
- function template[meta id-type]
- cpp11[meta cpp]
namespace std {
template <class Iterator>
class move_iterator {
public:
template <sentinel_for<Iterator> S>
friend constexpr bool operator==(const move_iterator& x,
const move_sentinel<S>& y); // (1) C++20
// (1)のoperator==により、以下のオーバーロードが使用可能になる (C++20)
template <sentinel_for<Iterator> S>
friend constexpr bool operator==(const move_sentinel<S>& x,
const move_iterator& y); // (2) C++20
};
template <class Iterator1, class Iterator2>
bool operator==(const move_iterator<Iterator1>& x,
const move_iterator<Iterator2>& y); // (3) C++11
template <class Iterator1, class Iterator2>
constexpr bool operator==(const move_iterator<Iterator1>& x,
const move_iterator<Iterator2>& y); // (3) C++17
}
- sentinel_for[link /reference/iterator/sentinel_for.md]
- move_sentinel[link /reference/iterator/move_sentinel.md]
2つのmove_iterator
オブジェクトが同じ要素を指しているかを判定する。
x.base() == y.base()
が有効であり、戻り値がbool
に変換可能であること。
return x.base() == y.base();
x.base()
とy.base()
はオーバーロードによって次のどちらか
C++20以降、これらの演算子により以下の演算子が使用可能になる。
operator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y)
operator!=(const move_iterator& x, const move_sentinel<S>& y)
operator!=(const move_sentinel<S>& x, const move_iterator& y)
#include <iostream>
#include <vector>
#include <memory>
#include <iterator>
int main()
{
std::vector<std::unique_ptr<int>> v;
for (int i = 0; i < 5; ++i)
v.emplace_back(new int(i));
auto it1 = std::make_move_iterator(v.begin());
auto it2 = std::make_move_iterator(v.begin());
if (it1 == it2) {
std::cout << "equal" << std::endl;
}
else {
std::cout << "not equal" << std::endl;
}
}
- v.emplace_back[link /reference/vector/vector/emplace_back.md]
- std::make_move_iterator[link /reference/iterator/make_move_iterator.md]
equal
- C++11
- Clang: ??
- GCC: 4.7.0 [mark verified]
- ICC: ??
- Visual C++: ??