Compare
Containers support the comparison operators ==
, !=
, <
, >
, <=
, >=
. The comparison of two containers happens on the elements of the containers. If you compare associative containers, their key is compared. Unordered associative containers support only the comparison operator ==
and !=
.
// containerComparison.cpp
...
#include
<array>
#include
<set>
#include
<unordered_map>
#include
<vector>
...
using
namespace
std
;
vector
<
int
>
vec1
{
1
,
2
,
3
,
4
};
vector
<
int
>
vec2
{
1
,
2
,
3
,
4
};
cout
<<
(
vec1
==
vec2
)
<<
endl
;
// true
array
<
int
,
4
>
arr1
{
1
,
2
,
3
,
4
};
array
<
int
,
4
>
arr2
{
1
,
2
,
3
,
4
};
cout
<<
(
arr1
==
arr2
)
<<
endl
;
// true
set
<
int
>
set1
{
1
,
2
,
3
,
4
};
set
<
int
>
set2
{
4
,
3
,
2
,
1
};
cout
<<
(
set1
==
set2
)
<<
endl
;
// true
set
<
int
>
set3
{
1
,
2
,
3
,
4
,
5
};
cout
<<
(
set1
<
set3
)
<<
endl
;
// true
set
<
int
>
set4...