-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[New Entry] Swap Method Maps C++ #5549
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @cigar-galaxy82 thank you for contributing to Codecademy Docs 😄
I've requested a few modifications, could you please review and make the changes at youe earliest convenience? Thank you! 😃
- 'paths/computer-science' | ||
--- | ||
|
||
The **`.swap()`** function exchanges the content of two maps of the same type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The **`.swap()`** function exchanges the content of two maps of the same type. | |
In C++, **`.swap()`** function exchanges the contents of two maps in constant time, provided the maps are of the same type, though their sizes may differ. |
map1.swap(map2); | ||
``` | ||
|
||
> **Note:** If `map1` and `map2` are not of the same type then a compilation error will occur. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
> **Note:** If `map1` and `map2` are not of the same type then a compilation error will occur. | |
> **Note:** If `map1` and `map2` are not of the same type (i.e., they do not have the same key and value types), a compilation error will occur because `std::map::swap()` requires both maps to have the same type. |
|
||
## Example | ||
|
||
The following example shows how the `swap()` method works: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following example shows how the `swap()` method works: | |
The following example shows how the `.swap()` function works: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we have mentioned it as a function above, lets stick to that
|
||
## Codebyte Example | ||
|
||
Running the below codebyte example shows how the `swap()` function works: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running the below codebyte example shows how the `swap()` function works: | |
Run the below codebyte example to know how the `.swap()` function works: |
prettified
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for contributing to Codecademy Docs @cigar-galaxy82 😄
The entry is ready to be merged 🚀
👋 @cigar-galaxy82 🎉 Your contribution(s) can be seen here: https://www.codecademy.com/resources/docs/cpp/maps/swap Please note it may take a little while for changes to become visible. |
Description
Issue Solved
#5357
Type of Change
Checklist
main
branch.Issues Solved
section.