From 8616d841ae645214803d246c53d7dff26c99ab19 Mon Sep 17 00:00:00 2001 From: Love Holmgren <143357495+hevolx@users.noreply.github.com> Date: Wed, 2 Jul 2025 19:44:00 +0200 Subject: [PATCH 1/3] Add max_size.md term entry for C++ Sets with description, syntax, example, and codebyte --- .../sets/terms/sets/max_size/max_size.md | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 content/cpp/concepts/sets/terms/sets/max_size/max_size.md diff --git a/content/cpp/concepts/sets/terms/sets/max_size/max_size.md b/content/cpp/concepts/sets/terms/sets/max_size/max_size.md new file mode 100644 index 00000000000..97d25066adc --- /dev/null +++ b/content/cpp/concepts/sets/terms/sets/max_size/max_size.md @@ -0,0 +1,68 @@ +--- +Title: 'max_size()' +Description: 'Returns the maximum number of elements a set can hold in C++.' +Subjects: + - 'C++' + - 'Data Structures' +Tags: + - 'sets' + - 'member functions' + - 'STL' +CatalogContent: + - 'learn-c-plus-plus' + - 'paths/c-plus-plus' +--- + +The **`max_size()`** method of a C++ set returns the maximum number of elements that the set can hold> + +## Syntax + +```cpp +size_type max_size() const noexcept; +``` + +- **Return Value**: A value of type `size_type` (typically `std::size_t`), representing the maximum n> +- **Parameters**: None. +- **Complexity**: Constant time, O(1). +- **Exception Safety**: `noexcept`, meaning it does not throw exceptions. +- **Notes**: The actual value is implementation-dependent and may vary across different systems or co> + +## Example + +To check the maximum number of elements a `std::set` can hold: + +```cpp +#include +#include + +int main() { + std::set mySet; + std::cout << "Maximum size of the set: " << mySet.max_size() << std::endl; + return 0; +} +``` + +**Output** (example, actual value depends on the system): +``` +Maximum size of the set: 4611686018427387903 +``` + +## Codebyte Example + +Below is a runnable example demonstrating `max_size()` with a `std::set`: + +```codebyte/cpp +#include +#include + +int main() { + std::set stringSet; + std::cout << "Maximum size of the string set: " << stringSet.max_size() << std::endl; + return 0; +} +``` + +**Expected Output** (example, actual value depends on the system): +``` +Maximum size of the string set: 2305843009213693951 +``` From def74aff6e648abd1b8310ba6d517ba5bac0ad1d Mon Sep 17 00:00:00 2001 From: Love Holmgren <143357495+hevolx@users.noreply.github.com> Date: Wed, 2 Jul 2025 19:59:11 +0200 Subject: [PATCH 2/3] correctly changed file-location from sets/max_size/max_size.md -> max_size/max_size.md --- content/cpp/concepts/sets/terms/{sets => }/max_size/max_size.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename content/cpp/concepts/sets/terms/{sets => }/max_size/max_size.md (100%) diff --git a/content/cpp/concepts/sets/terms/sets/max_size/max_size.md b/content/cpp/concepts/sets/terms/max_size/max_size.md similarity index 100% rename from content/cpp/concepts/sets/terms/sets/max_size/max_size.md rename to content/cpp/concepts/sets/terms/max_size/max_size.md From b466f9b472e3c0e51c6e55c555863daf5f3e5fa4 Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Sat, 5 Jul 2025 12:31:56 +0530 Subject: [PATCH 3/3] content tweak and changed file name --- .../concepts/sets/terms/max-size/max-size.md | 70 +++++++++++++++++++ .../concepts/sets/terms/max_size/max_size.md | 68 ------------------ 2 files changed, 70 insertions(+), 68 deletions(-) create mode 100644 content/cpp/concepts/sets/terms/max-size/max-size.md delete mode 100644 content/cpp/concepts/sets/terms/max_size/max_size.md diff --git a/content/cpp/concepts/sets/terms/max-size/max-size.md b/content/cpp/concepts/sets/terms/max-size/max-size.md new file mode 100644 index 00000000000..8775db2d6b5 --- /dev/null +++ b/content/cpp/concepts/sets/terms/max-size/max-size.md @@ -0,0 +1,70 @@ +--- +Title: 'max_size()' +Description: 'Returns the maximum number of elements the set can hold' +Subjects: + - 'Computer Science' + - 'Data Science' +Tags: + - 'Functions' + - 'Sets' + - 'STL' +CatalogContent: + - 'learn-c-plus-plus' + - 'paths/computer-science' +--- + +**`max_size()`** is a member function of C++ containers like `std::set` that returns the maximum number of elements the container can hold, based on the system or allocator limitations. It does not reflect the current size, but the theoretical upper bound. + +## Syntax + +```pseudo +set_name.max_size() +``` + +**Parameters:** + +This function does not take any parameters. + +**Return value:** + +Returns an integral value of type `size_type` (usually `std::size_t`) representing the maximum number of elements the set can theoretically contain, based on system or allocator limitations. + +## Example: Using `max_size()` with `std::set` + +The following code checks the maximum number of elements a `std::set` can theoretically hold, depending on system and allocator limits: + +```cpp +#include +#include + +int main() { + std::set mySet; + std::cout << "Maximum size of the set: " << mySet.max_size() << std::endl; + return 0; +} +``` + +The possible output of this code is: + +```shell +Maximum size of the set: 4611686018427387903 +``` + +> **Note:** The actual result may vary by system and compiler. + +## Codebyte Example: Using `max_size()` with `std::set` + +Here is a runnable example that demonstrates how to use `max_size()` with a `std::set` to check its theoretical capacity: + +```codebyte/cpp +#include +#include +#include + +int main() { + std::set stringSet; + std::cout << "Maximum size of the string set: " << stringSet.max_size() << std::endl; + return 0; +} + +``` diff --git a/content/cpp/concepts/sets/terms/max_size/max_size.md b/content/cpp/concepts/sets/terms/max_size/max_size.md deleted file mode 100644 index 97d25066adc..00000000000 --- a/content/cpp/concepts/sets/terms/max_size/max_size.md +++ /dev/null @@ -1,68 +0,0 @@ ---- -Title: 'max_size()' -Description: 'Returns the maximum number of elements a set can hold in C++.' -Subjects: - - 'C++' - - 'Data Structures' -Tags: - - 'sets' - - 'member functions' - - 'STL' -CatalogContent: - - 'learn-c-plus-plus' - - 'paths/c-plus-plus' ---- - -The **`max_size()`** method of a C++ set returns the maximum number of elements that the set can hold> - -## Syntax - -```cpp -size_type max_size() const noexcept; -``` - -- **Return Value**: A value of type `size_type` (typically `std::size_t`), representing the maximum n> -- **Parameters**: None. -- **Complexity**: Constant time, O(1). -- **Exception Safety**: `noexcept`, meaning it does not throw exceptions. -- **Notes**: The actual value is implementation-dependent and may vary across different systems or co> - -## Example - -To check the maximum number of elements a `std::set` can hold: - -```cpp -#include -#include - -int main() { - std::set mySet; - std::cout << "Maximum size of the set: " << mySet.max_size() << std::endl; - return 0; -} -``` - -**Output** (example, actual value depends on the system): -``` -Maximum size of the set: 4611686018427387903 -``` - -## Codebyte Example - -Below is a runnable example demonstrating `max_size()` with a `std::set`: - -```codebyte/cpp -#include -#include - -int main() { - std::set stringSet; - std::cout << "Maximum size of the string set: " << stringSet.max_size() << std::endl; - return 0; -} -``` - -**Expected Output** (example, actual value depends on the system): -``` -Maximum size of the string set: 2305843009213693951 -```