描述
它是一個關係運算符。
聲明
以下是 std::rel_ops 函數的聲明。
namespace rel_ops {
template <class T> bool operator!= (const T& x, const T& y);
template <class T> bool operator> (const T& x, const T& y);
template <class T> bool operator<= (const T& x, const T& y);
template <class T> bool operator>= (const T& x, const T& y);
}
C++11
namespace rel_ops {
template <class T> bool operator!= (const T& x, const T& y);
template <class T> bool operator> (const T& x, const T& y);
template <class T> bool operator<= (const T& x, const T& y);
template <class T> bool operator>= (const T& x, const T& y);
}
參數
T─ 它是一個類型,該類型應為 EqualityComparable。
返回值
空
異常
空
數據競爭
空
示例
在下麵的例子中解釋了 std::rel_ops 函數。
#include <iostream>
#include <utility>
#include <cmath>
class vector2d {
public:
double x,y;
vector2d (double px,double py):x(px), y(py) {}
double length() const {return std::sqrt(x*x+y*y);}
bool operator==(const vector2d& rhs) const {return length()==rhs.length();}
bool operator< (const vector2d& rhs) const {return length()< rhs.length();}
};
int main () {
using namespace std::rel_ops;
vector2d a (10,10);
vector2d b (15,20);
std::cout << std::boolalpha;
std::cout << "(a>b) is " << (a<b) << '\n';
std::cout << "(a<b) is " << (a>b) << '\n';
return 0;
}
讓我們編譯並運行上麵的程序,這將產生以下結果——
(a>b) is true (a<b) is false
相關用法
- C++ utility swap用法及代碼示例
- C++ utility piecewise_construct用法及代碼示例
- C++ utility move用法及代碼示例
- C++ utility make_pair用法及代碼示例
- C++ utility move_if_noexcept用法及代碼示例
- C++ utility forward用法及代碼示例
- C++ utility declval用法及代碼示例
- C++ unordered_map cbegin用法及代碼示例
- C++ unordered_set max_bucket_count()用法及代碼示例
- C++ unordered_multimap reserve()用法及代碼示例
- C++ unordered_multimap swap()用法及代碼示例
- C++ unordered_multiset get_allocator用法及代碼示例
- C++ unordered_set swap()用法及代碼示例
- C++ unordered_multimap rehash()用法及代碼示例
- C++ unordered_set equal_range用法及代碼示例
- C++ unordered_map rehash用法及代碼示例
- C++ unordered_map emplace_hint()用法及代碼示例
- C++ unordered_map key_eq()用法及代碼示例
- C++ unordered_multiset cend()用法及代碼示例
- C++ unordered_multimap get_allocator用法及代碼示例
注:本文由純淨天空篩選整理自 C++ Utility Library - rel_ops Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。