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