- memory[meta header]
- std[meta namespace]
- function template[meta id-type]
- cpp11[meta cpp]
namespace std {
// operator==により、以下の演算子が使用可能になる (C++20)
template <class T1, class D1, class T2, class D2>
bool operator!=(const unique_ptr<T1, D1>& a, const unique_ptr<T2, D2>& b); // (1) C++11
template <class T1, class D1, class T2, class D2>
constexpr bool operator!=(const unique_ptr<T1, D1>& a, const unique_ptr<T2, D2>& b); // (1) C++23
template <class T, class D>
bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept; // (2) C++11
template <class T, class D>
constexpr bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept; // (2) C++23
template <class T, class D>
bool operator!=(nullptr_t, const unique_ptr<T, D>& x) noexcept; // (3) C++11
template <class T, class D>
constexpr bool operator!=(nullptr_t, const unique_ptr<T, D>& x) noexcept; // (3) C++23
}非等値比較。
#include <iostream>
#include <memory>
int main()
{
std::unique_ptr<int> p1(new int(3));
std::unique_ptr<int> p2(new int(3));
if (p1 != p2) {
std::cout << "not equal" << std::endl;
}
std::unique_ptr<int> p3(new int(3));
if (p3 != nullptr) {
std::cout << "p3 is not nullptr" << std::endl;
}
if (nullptr != p3) {
std::cout << "p3 is not nullptr" << std::endl;
}
}not equal
p3 is not nullptr
p3 is not nullptr
- C++11
- GCC: 4.4.7 (
nullptrバージョン以外) [mark verified], 4.6.4 [mark verified] - Clang: 3.0 [mark verified]
- ICC: ?
- Visual C++: 2010 [mark verified], 2012 [mark verified], 2013 [mark verified]
- 2012までは
nullptrバージョンがない。
- 2012までは
- P1614R2 The Mothership has Landed
- C++20での三方比較演算子の追加と、関連する演算子の自動導出
- P2273R3 Making
std::unique_ptrconstexpr