Skip to content
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

Merged
merged 7 commits into from
Oct 28, 2024

Conversation

cigar-galaxy82
Copy link
Contributor

@cigar-galaxy82 cigar-galaxy82 commented Oct 22, 2024

Description

Issue Solved

#5357

Type of Change

  • Adding a new entry

Checklist

  • All writings are my own.
  • My entry follows the Codecademy Docs style guide.
  • My changes generate no new warnings.
  • I have performed a self-review of my own writing and code.
  • I have checked my entry and corrected any misspellings.
  • I have made corresponding changes to the documentation if needed.
  • I have confirmed my changes are not being pushed from my forked main branch.
  • I have confirmed that I'm pushing from a new branch named after the changes I'm making.
  • I have linked any issues that are relevant to this PR in the Issues Solved section.

@mamtawardhani mamtawardhani self-assigned this Oct 23, 2024
@mamtawardhani mamtawardhani added c++ C++ entries new entry New entry or entries status: under review Issue or PR is currently being reviewed labels Oct 23, 2024
Copy link
Collaborator

@mamtawardhani mamtawardhani left a 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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

content/cpp/concepts/maps/terms/swap/swap.md Show resolved Hide resolved
map1.swap(map2);
```

> **Note:** If `map1` and `map2` are not of the same type then a compilation error will occur.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
> **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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The following example shows how the `swap()` method works:
The following example shows how the `.swap()` function works:

Copy link
Collaborator

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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Running the below codebyte example shows how the `swap()` function works:
Run the below codebyte example to know how the `.swap()` function works:

Copy link
Collaborator

@mamtawardhani mamtawardhani left a 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 🚀

@mamtawardhani mamtawardhani linked an issue Oct 28, 2024 that may be closed by this pull request
3 tasks
@mamtawardhani mamtawardhani merged commit 16fcf59 into Codecademy:main Oct 28, 2024
6 checks passed
Copy link

👋 @cigar-galaxy82
You have contributed to Codecademy Docs, and we would like to know more about you and your experience.
Please take a minute to fill out this four question survey to help us better understand Docs contributions and how we can improve the experience for you and our learners.
Thank you for your help!

🎉 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.
If you're appearing as anonymous and want to be credited, see here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Term Entry] C++ Maps Swap()
2 participants