9.2.7. Relational Operators
Every container type supports the equality operators (==
and !=
); all the containers except the unordered associative containers also support the relational operators (>
, >=
, <
, <=
). The right- and left-hand operands must be the same kind of container and must hold elements of the same type. That is, we can compare a vector<int>
only with another vector<int>
. We cannot compare a vector<int>
with a list<int>
or a vector<double>
.
Comparing two containers performs a pairwise comparison of the elements. These operators work similarly to the string
relationals (§ 3.2.2, p. 88):
• If both containers are the same size and all the elements are equal, then the two containers are equal; otherwise, they are unequal.
• If the ...
Get C++ Primer, Fifth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.