std::relational operators (vector)
(1) |
template <class T, class Alloc>
bool operator== (const vector<T,Alloc>& lhs, const vector<T,Alloc>& rhs);
|
---|---|
(2) |
template <class T, class Alloc>
bool operator!= (const vector<T,Alloc>& lhs, const vector<T,Alloc>& rhs);
|
(3) |
template <class T, class Alloc>
bool operator< (const vector<T,Alloc>& lhs, const vector<T,Alloc>& rhs);
|
(4) |
template <class T, class Alloc>
bool operator<= (const vector<T,Alloc>& lhs, const vector<T,Alloc>& rhs);
|
(5) |
template <class T, class Alloc>
bool operator> (const vector<T,Alloc>& lhs, const vector<T,Alloc>& rhs);
(6)template <class T, class Alloc>
bool operator>= (const vector<T,Alloc>& lhs, const vector<T,Alloc>& rhs);
|
Performs the appropriate comparison operation between the vector containers lhs and rhs.
对两个vector数组执行合适的比较操作。
The equality comparison (operator==
) is performed by first comparing sizes, and
if they match, the elements are compared sequentially using operator==
, stopping at the first mismatch (as if using algorithm equal).
比较相等的操作是首先比较两者的大小,然后使用==依次比较他们的元素,直到第一次失配。
The less-than comparison (operator<
) behaves as if using algorithm lexicographical_compare
,
which compares the elements sequentially using operator<
in a reciprocal manner (i.e., checking both a<b
and b<a
) and stopping at the first occurrence.
比较器<的行为就像lexicographical_compare的一样,依次使用<比较两者相互之间的元素(不管大小是否相同),以及在第一次失败时停止比较。
The other operations also use the operators ==
and <
internally to compare the elements, behaving as if the following equivalent operations were performed:
其他的操作也是令用==已经<进行比较,行为就和下面的等价列表一样。
operation | equivalent operation |
---|---|
a!=b |
!(a==b) |
a>b |
b<a |
a<=b |
!(b<a) |
a>=b |
!(a<b) |
These operators are overloaded in header <vector>.
Parameters
-
lhs, rhs
vector containers (to the left- and right-hand side
of the operator, respectively), having both the same template parameters (Tand Alloc).具有相同类型的两个vector.
Return Value
true if the condition holds, and false otherwise.
Example
|
|
Output:
foo and bar are not equal
foo is less than bar
foo is less than or equal to bar
|
Complexity
For (1) and (2), constant if the sizes of lhs and rhs differ,
and up to linear in that size (equality comparisons) otherwise.
对于(1),(2)来说,如果两者大小不同,则是常量时间复杂的,否则时和大小相关的线性时间复杂的。
For the others, up to linear in the smaller size (each representing two comparisons with operator<
).
对于其他情况,和最小的那个size线性相关。
Iterator validity
No changes.
Data races
Both containers, lhs and rhs, are accessed.
所有的容器都将被访问。
Up to all of their contained elements may be accessed.
容器的所有元素都可能被访问。
In any case, the function cannot modify its arguments (const-qualified).
不管任何情况下,该方法都不会修改其元素。
Exception safety
If the type of the elements supports the appropriate operation with no-throw guarantee, the function never throws exceptions (no-throw guarantee).
如果元素的比较操作不会抛出异常,那么该函数也不会抛出异常。
//翻译的不好的地方请多多指导,可以在下面留言或者点击左上方邮件地址给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。
转载请注明出处:http://blog.csdn.net/qq844352155
2014-8-20
于GDUT