From 5b99b50742488d597a7b7b6e201f5db712175541 Mon Sep 17 00:00:00 2001 From: Arsivnet Date: Sat, 29 Apr 2023 13:57:16 +0259 Subject: [PATCH 1/2] added destroy.md --- algorithm/destroy.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 algorithm/destroy.md diff --git a/algorithm/destroy.md b/algorithm/destroy.md new file mode 100644 index 00000000..eaf8b99d --- /dev/null +++ b/algorithm/destroy.md @@ -0,0 +1,27 @@ +# destroy + +**Description** : Destroys the elements of a vector in a given range. + +**Example** : +```cpp +struct Object { + int value; + ~Object() + { + std::cout << value << " destructed\n"; + } +}; + +std::vector myVector (8); + +//manually giving values to the objects +for(int i = 0; i < 8; i++) + { + myVector[i].value = i; + } + +auto ptr = &myVector; + +std::destroy(ptr, ptr + 8); +``` + From 04d4829eaa67445a796fd8f886f017335022b64d Mon Sep 17 00:00:00 2001 From: Arsivnet Date: Sat, 29 Apr 2023 15:33:58 +0259 Subject: [PATCH 2/2] fixed according to style guide --- algorithm/destroy.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/algorithm/destroy.md b/algorithm/destroy.md index eaf8b99d..cc8da99b 100644 --- a/algorithm/destroy.md +++ b/algorithm/destroy.md @@ -4,10 +4,9 @@ **Example** : ```cpp -struct Object { +struct Object{ int value; - ~Object() - { + ~Object(){ std::cout << value << " destructed\n"; } }; @@ -15,11 +14,13 @@ struct Object { std::vector myVector (8); //manually giving values to the objects -for(int i = 0; i < 8; i++) - { + +for(int i = 0; i < 8; i++){ myVector[i].value = i; } +//assigning the pointer to a variable for readibility + auto ptr = &myVector; std::destroy(ptr, ptr + 8);