From 35b8140cb90126d3d15351476503e89829d8d0b9 Mon Sep 17 00:00:00 2001 From: bvillav-a11y Date: Wed, 3 Dec 2025 13:28:12 -0300 Subject: [PATCH 1/4] Add max_size entry --- .../unordered-set/terms/max-size/max-size.md | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 content/cpp/concepts/unordered-set/terms/max-size/max-size.md diff --git a/content/cpp/concepts/unordered-set/terms/max-size/max-size.md b/content/cpp/concepts/unordered-set/terms/max-size/max-size.md new file mode 100644 index 00000000000..d0243869147 --- /dev/null +++ b/content/cpp/concepts/unordered-set/terms/max-size/max-size.md @@ -0,0 +1,95 @@ +--- +Title: 'max_size()' # Required; the file name should be the same as the title, but lowercase, with dashes instead of spaces, and all punctuation removed +Description: 'Returns the maximum number of elements that the container can theoretically hold.' # Required; ideally under 150 characters and starts with a present-tense verb (used in search engine results and content previews) +Subjects: # Please only use Subjects in the subjects.md file (https://github.com/Codecademy/docs/blob/main/documentation/subjects.md). If that list feels insufficient, feel free to create a new Subject and add it to subjects.md in your PR! + - 'Computer Science' + - 'Code Foundations' +Tags: # Please only use Tags in the tags.md file (https://github.com/Codecademy/docs/blob/main/documentation/tags.md). If that list feels insufficient, feel free to create a new Tag and add it to tags.md in your PR! + - 'Methods' + - 'Containers' + - 'STL' +CatalogContent: # Please use course/path landing page slugs, rather than linking to individual content items. If listing multiple items, please put the most relevant one first + - 'learn-c-plus-plus' + - 'paths/computer-science' +--- + +The **`.max_size()`** method returns the maximum number of elements that a container can theoretically hold. This value depends on system and library implementation limitations, not the actual available memory. + +## Syntax + +```pseudo +unordered_set_name.max_size() +``` + +- `unordered_set_name`: The name of the `unordered_set` container. + +The method returns a value of type `size_type`, representing the theoretical maximum number of elements. + +## Example 1: Basic Usage + +```cpp +#include +#include + +int main() { + std::unordered_set numbers; + + std::cout << "Maximum size: " << numbers.max_size() << std::endl; + + return 0; +} +``` + +This example outputs the maximum possible size of the `unordered_set`: + +```shell +Maximum size: 576460752303423487 +``` + +> **Note:** The actual value may vary depending on the system and implementation. + + +## Example 2: Different Data Types + +```cpp +#include +#include + +int main() { + std::unordered_set int_set; + std::unordered_set double_set; + std::unordered_set char_set; + + std::cout << "int max_size: " << int_set.max_size() << std::endl; + std::cout << "double max_size: " << double_set.max_size() << std::endl; + std::cout << "char max_size: " << char_set.max_size() << std::endl; + + return 0; +} +``` + +This demonstrates that `max_size()` can vary based on the element type: + +```shell +int max_size: 576460752303423487 +double max_size: 384307168202282325 +char max_size: 1152921504606846975 +``` + +## Codebyte Example + + +```codebyte/cpp +#include +#include + +int main() { + std::unordered_set fruits = {"apple", "banana", "cherry"}; + + std::cout << "Current size: " << fruits.size() << std::endl; + std::cout << "Maximum size: " << fruits.max_size() << std::endl; + std::cout << "Available capacity: " << fruits.max_size() - fruits.size() << std::endl; + + return 0; +} +``` \ No newline at end of file From 1e15d86d8f447d81ef8197e630980630599489db Mon Sep 17 00:00:00 2001 From: bvillav-a11y Date: Thu, 4 Dec 2025 10:01:07 -0300 Subject: [PATCH 2/4] Change folder name --- .../unordered-set/terms/max_size/max_size.md | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 content/cpp/concepts/unordered-set/terms/max_size/max_size.md diff --git a/content/cpp/concepts/unordered-set/terms/max_size/max_size.md b/content/cpp/concepts/unordered-set/terms/max_size/max_size.md new file mode 100644 index 00000000000..d0243869147 --- /dev/null +++ b/content/cpp/concepts/unordered-set/terms/max_size/max_size.md @@ -0,0 +1,95 @@ +--- +Title: 'max_size()' # Required; the file name should be the same as the title, but lowercase, with dashes instead of spaces, and all punctuation removed +Description: 'Returns the maximum number of elements that the container can theoretically hold.' # Required; ideally under 150 characters and starts with a present-tense verb (used in search engine results and content previews) +Subjects: # Please only use Subjects in the subjects.md file (https://github.com/Codecademy/docs/blob/main/documentation/subjects.md). If that list feels insufficient, feel free to create a new Subject and add it to subjects.md in your PR! + - 'Computer Science' + - 'Code Foundations' +Tags: # Please only use Tags in the tags.md file (https://github.com/Codecademy/docs/blob/main/documentation/tags.md). If that list feels insufficient, feel free to create a new Tag and add it to tags.md in your PR! + - 'Methods' + - 'Containers' + - 'STL' +CatalogContent: # Please use course/path landing page slugs, rather than linking to individual content items. If listing multiple items, please put the most relevant one first + - 'learn-c-plus-plus' + - 'paths/computer-science' +--- + +The **`.max_size()`** method returns the maximum number of elements that a container can theoretically hold. This value depends on system and library implementation limitations, not the actual available memory. + +## Syntax + +```pseudo +unordered_set_name.max_size() +``` + +- `unordered_set_name`: The name of the `unordered_set` container. + +The method returns a value of type `size_type`, representing the theoretical maximum number of elements. + +## Example 1: Basic Usage + +```cpp +#include +#include + +int main() { + std::unordered_set numbers; + + std::cout << "Maximum size: " << numbers.max_size() << std::endl; + + return 0; +} +``` + +This example outputs the maximum possible size of the `unordered_set`: + +```shell +Maximum size: 576460752303423487 +``` + +> **Note:** The actual value may vary depending on the system and implementation. + + +## Example 2: Different Data Types + +```cpp +#include +#include + +int main() { + std::unordered_set int_set; + std::unordered_set double_set; + std::unordered_set char_set; + + std::cout << "int max_size: " << int_set.max_size() << std::endl; + std::cout << "double max_size: " << double_set.max_size() << std::endl; + std::cout << "char max_size: " << char_set.max_size() << std::endl; + + return 0; +} +``` + +This demonstrates that `max_size()` can vary based on the element type: + +```shell +int max_size: 576460752303423487 +double max_size: 384307168202282325 +char max_size: 1152921504606846975 +``` + +## Codebyte Example + + +```codebyte/cpp +#include +#include + +int main() { + std::unordered_set fruits = {"apple", "banana", "cherry"}; + + std::cout << "Current size: " << fruits.size() << std::endl; + std::cout << "Maximum size: " << fruits.max_size() << std::endl; + std::cout << "Available capacity: " << fruits.max_size() - fruits.size() << std::endl; + + return 0; +} +``` \ No newline at end of file From 5a6d242af2a81fb3279a03fbf4e623e1e6ac03e3 Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Fri, 5 Dec 2025 13:19:33 +0530 Subject: [PATCH 3/4] Revise max_size() documentation and examples Updated the max_size documentation to clarify its usage and examples. Adjusted return values and improved syntax for better readability. --- .../unordered-set/terms/max-size/max-size.md | 48 +++++++++++-------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/content/cpp/concepts/unordered-set/terms/max-size/max-size.md b/content/cpp/concepts/unordered-set/terms/max-size/max-size.md index d0243869147..59f455474d0 100644 --- a/content/cpp/concepts/unordered-set/terms/max-size/max-size.md +++ b/content/cpp/concepts/unordered-set/terms/max-size/max-size.md @@ -1,19 +1,19 @@ --- -Title: 'max_size()' # Required; the file name should be the same as the title, but lowercase, with dashes instead of spaces, and all punctuation removed -Description: 'Returns the maximum number of elements that the container can theoretically hold.' # Required; ideally under 150 characters and starts with a present-tense verb (used in search engine results and content previews) -Subjects: # Please only use Subjects in the subjects.md file (https://github.com/Codecademy/docs/blob/main/documentation/subjects.md). If that list feels insufficient, feel free to create a new Subject and add it to subjects.md in your PR! - - 'Computer Science' +Title: 'max_size()' +Description: 'Returns the maximum number of elements that the container can theoretically hold.' +Subjects: - 'Code Foundations' -Tags: # Please only use Tags in the tags.md file (https://github.com/Codecademy/docs/blob/main/documentation/tags.md). If that list feels insufficient, feel free to create a new Tag and add it to tags.md in your PR! - - 'Methods' + - 'Computer Science' +Tags: - 'Containers' + - 'Methods' - 'STL' -CatalogContent: # Please use course/path landing page slugs, rather than linking to individual content items. If listing multiple items, please put the most relevant one first +CatalogContent: - 'learn-c-plus-plus' - 'paths/computer-science' --- -The **`.max_size()`** method returns the maximum number of elements that a container can theoretically hold. This value depends on system and library implementation limitations, not the actual available memory. +The **`.max_size()`** member function returns the maximum number of elements a container can theoretically hold. This limit depends on the system and the implementation of the standard library, not on actual available memory. ## Syntax @@ -21,21 +21,27 @@ The **`.max_size()`** method returns the maximum number of elements that a conta unordered_set_name.max_size() ``` -- `unordered_set_name`: The name of the `unordered_set` container. +**Parameters:** + +This function takes no parameters. + +**Return value:** The method returns a value of type `size_type`, representing the theoretical maximum number of elements. ## Example 1: Basic Usage +In this example the program prints the maximum number of elements an `unordered_set` can theoretically hold: + ```cpp #include #include int main() { std::unordered_set numbers; - + std::cout << "Maximum size: " << numbers.max_size() << std::endl; - + return 0; } ``` @@ -43,14 +49,15 @@ int main() { This example outputs the maximum possible size of the `unordered_set`: ```shell -Maximum size: 576460752303423487 +Maximum size: 1152921504606846975 ``` > **Note:** The actual value may vary depending on the system and implementation. - ## Example 2: Different Data Types +In this example the `max_size()` value is shown for `unordered_set` containers holding different data types: + ```cpp #include #include @@ -59,11 +66,11 @@ int main() { std::unordered_set int_set; std::unordered_set double_set; std::unordered_set char_set; - + std::cout << "int max_size: " << int_set.max_size() << std::endl; std::cout << "double max_size: " << double_set.max_size() << std::endl; std::cout << "char max_size: " << char_set.max_size() << std::endl; - + return 0; } ``` @@ -71,13 +78,14 @@ int main() { This demonstrates that `max_size()` can vary based on the element type: ```shell -int max_size: 576460752303423487 -double max_size: 384307168202282325 +int max_size: 1152921504606846975 +double max_size: 1152921504606846975 char max_size: 1152921504606846975 ``` ## Codebyte Example +In this example the program compares the current size of an `unordered_set` with its theoretical maximum: ```codebyte/cpp #include @@ -85,11 +93,11 @@ char max_size: 1152921504606846975 int main() { std::unordered_set fruits = {"apple", "banana", "cherry"}; - + std::cout << "Current size: " << fruits.size() << std::endl; std::cout << "Maximum size: " << fruits.max_size() << std::endl; std::cout << "Available capacity: " << fruits.max_size() - fruits.size() << std::endl; - + return 0; } -``` \ No newline at end of file +``` From 7706f1e8c7925a066723343e2031f31548ed78cd Mon Sep 17 00:00:00 2001 From: bvillav-a11y Date: Fri, 5 Dec 2025 14:20:49 -0300 Subject: [PATCH 4/4] Remove duplicate max_size folder, keeping max-size --- .../unordered-set/terms/max_size/max_size.md | 95 ------------------- 1 file changed, 95 deletions(-) delete mode 100644 content/cpp/concepts/unordered-set/terms/max_size/max_size.md diff --git a/content/cpp/concepts/unordered-set/terms/max_size/max_size.md b/content/cpp/concepts/unordered-set/terms/max_size/max_size.md deleted file mode 100644 index d0243869147..00000000000 --- a/content/cpp/concepts/unordered-set/terms/max_size/max_size.md +++ /dev/null @@ -1,95 +0,0 @@ ---- -Title: 'max_size()' # Required; the file name should be the same as the title, but lowercase, with dashes instead of spaces, and all punctuation removed -Description: 'Returns the maximum number of elements that the container can theoretically hold.' # Required; ideally under 150 characters and starts with a present-tense verb (used in search engine results and content previews) -Subjects: # Please only use Subjects in the subjects.md file (https://github.com/Codecademy/docs/blob/main/documentation/subjects.md). If that list feels insufficient, feel free to create a new Subject and add it to subjects.md in your PR! - - 'Computer Science' - - 'Code Foundations' -Tags: # Please only use Tags in the tags.md file (https://github.com/Codecademy/docs/blob/main/documentation/tags.md). If that list feels insufficient, feel free to create a new Tag and add it to tags.md in your PR! - - 'Methods' - - 'Containers' - - 'STL' -CatalogContent: # Please use course/path landing page slugs, rather than linking to individual content items. If listing multiple items, please put the most relevant one first - - 'learn-c-plus-plus' - - 'paths/computer-science' ---- - -The **`.max_size()`** method returns the maximum number of elements that a container can theoretically hold. This value depends on system and library implementation limitations, not the actual available memory. - -## Syntax - -```pseudo -unordered_set_name.max_size() -``` - -- `unordered_set_name`: The name of the `unordered_set` container. - -The method returns a value of type `size_type`, representing the theoretical maximum number of elements. - -## Example 1: Basic Usage - -```cpp -#include -#include - -int main() { - std::unordered_set numbers; - - std::cout << "Maximum size: " << numbers.max_size() << std::endl; - - return 0; -} -``` - -This example outputs the maximum possible size of the `unordered_set`: - -```shell -Maximum size: 576460752303423487 -``` - -> **Note:** The actual value may vary depending on the system and implementation. - - -## Example 2: Different Data Types - -```cpp -#include -#include - -int main() { - std::unordered_set int_set; - std::unordered_set double_set; - std::unordered_set char_set; - - std::cout << "int max_size: " << int_set.max_size() << std::endl; - std::cout << "double max_size: " << double_set.max_size() << std::endl; - std::cout << "char max_size: " << char_set.max_size() << std::endl; - - return 0; -} -``` - -This demonstrates that `max_size()` can vary based on the element type: - -```shell -int max_size: 576460752303423487 -double max_size: 384307168202282325 -char max_size: 1152921504606846975 -``` - -## Codebyte Example - - -```codebyte/cpp -#include -#include - -int main() { - std::unordered_set fruits = {"apple", "banana", "cherry"}; - - std::cout << "Current size: " << fruits.size() << std::endl; - std::cout << "Maximum size: " << fruits.max_size() << std::endl; - std::cout << "Available capacity: " << fruits.max_size() - fruits.size() << std::endl; - - return 0; -} -``` \ No newline at end of file