diff --git a/algorithm/destroy.md b/algorithm/destroy.md new file mode 100644 index 00000000..cc8da99b --- /dev/null +++ b/algorithm/destroy.md @@ -0,0 +1,28 @@ +# 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; + } + +//assigning the pointer to a variable for readibility + +auto ptr = &myVector; + +std::destroy(ptr, ptr + 8); +``` +