Javatpoint Logo
Javatpoint Logo

C++ std operator==

C++ std operator== is a non-member overloaded function of set in C++. This function is used to check whether the two sets are equal or not.

Note: Comparison between set objects is based on a pair wise comparison of the elements. Two sets are equal if they have the same number of elements and their corresponding elements have the same values. Otherwise they are not equal.

Syntax

Parameter

lhs: First set object.

rhs: Second set object.

Return value

It returns true if the left side of the set object is equal to the right side of the set object otherwise false.

Complexity

Complexity will be constant, if the size of lhs and rhs is different.

Otherwise, up to linear in the size of lhs and rhs.

Iterator validity

No changes.

Data Races

Containers, lhs and rhs are accessed.

Concurrently accessing the elements of unmodified set objects is always safe means their elements are immutable.

Exception Safety

This function does not throw an exception.

Example 1

Let's see the simple example to check whether the two sets are equal or not:

Output:

Both sets are equal.
Both sets are not equal.

In the above example, set m1 and m2 are empty. Therefore operator== will return true and after adding one element in set m1 size of m1 becomes different to size of m2. Therefore, it will return false.

Example 2

Let's see a simple example:

Output:

The sets m1 and m2 are not equal.
The sets m1 and m3 are equal.

Example 3

Let's see a simple example:

Output:

1
0

In the above example, if sets s1 and s2 are equal then it will return 1 otherwise 0.

Example 4

Output:

1).
---------Login----------

Enter the password: 
xyz
Password you have entered: 
xyz
Password stored in the system :
xyz@123

Incorrect Password...


2).
---------Login----------

Enter the password: 
xyz@123
Password you have entered: 
xyz@123
Password stored in the system :
xyz@123

Welcome to your Page...

In the above example, there are two sets m1 and m2. m1 contains password and second set m2 stores user's entered password. It checks whether the both set has same elements or not. If password will match then login is successful otherwise login fails.


Next TopicSet operator!=





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA