C++ Tuple 库 - relational operators (tuple)
描述
它包含元组的关系运算符,并在元组对象 lhs 和 rhs 之间执行适当的比较操作。
声明
以下是 std::relational 运算符(元组)的声明
C++98
template<class... TTypes, class... UTypes> bool operator== ( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs); template<class... TTypes, class... UTypes> bool operator!= ( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs); template<class... TTypes, class... UTypes> bool operator< ( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs); template<class... TTypes, class... UTypes> bool operator> ( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs); template<class... TTypes, class... UTypes> bool operator>= ( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs); template<class... TTypes, class... UTypes> bool operator<= ( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs);
C++11
template<class... TTypes, class... UTypes> bool operator== ( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs); template<class... TTypes, class... UTypes> bool operator!= ( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs); template<class... TTypes, class... UTypes> bool operator< ( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs); template<class... TTypes, class... UTypes> bool operator> ( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs); template<class... TTypes, class... UTypes> bool operator>= ( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs); template<class... TTypes, class... UTypes> bool operator<= ( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs); </pre>
参数
lhs, rhs − 这些是元组对象。
返回值
如果条件成立,则返回 true,否则返回 false。
异常
No-throw guarantee − 这个成员函数从不抛出异常。
数据竞争
lhs 和 rhs 被访问,并且最多访问其所有成员。
示例
在下面的 std::relational 运算符(元组)示例中。
#include <iostream> #include <tuple> int main () { std::tuple<int,char> a (100,'x'); std::tuple<char,char> b (100,'x'); std::tuple<char,char> c (100,'y'); if (a==b) std::cout << "a and b are equal\n"; if (b!=c) std::cout << "b and c are not equal\n"; if (b<c) std::cout << "b is less than c\n"; if (c>a) std::cout << "c is greater than a\n"; if (a<=c) std::cout << "a is less than or equal to c\n"; if (c>=b) std::cout << "c is greater than or equal to b\n"; return 0; }
输出应该是这样的 −
a and b are equal b and c are not equal b is less than c c is greater than a a is less than or equal to c c is greater than or equal to b