// IMP or we can use make_array or make_unique or make_Shared insted of this below

which one is the recent one make unique or make array and which one is best or any 
other then this which is more efficient?

std::make_unique is a function template that is part of the C++ standard library,
it was introduced in C++14. It creates and returns a unique pointer to an object 
of a specified type, with a specified set of constructor arguments.

make_array is a custom function template that you can create, it creates and
returns a unique pointer to a dynamic array of a specified type.

Both std::make_unique and make_array are efficient in creating and managing the
lifetimes of dynamically allocated objects, and the choice between them depends
on the specific use case and personal preference.

std::make_unique is more flexible as it can be used to create objects of any type 
and it takes any constructor arguments, while make_array is limited to creating
dynamic arrays.

std::make_unique can be used to create any type of object, not just arrays, so
if you're going to use the function to create dynamic arrays, you need to pass
in the array size as an additional argument.

make_array is more explicit in that it is specifically for creating dynamic
arrays, and it only takes one argument which is the size of the array.

In summary, if you need to create dynamic arrays, make_array can be a more clear
and explicit choice, but if you need to create objects of different types and need
more flexibility, std::make_unique is a good option.

______________________________________________________________________________

dynamic array with smart pointer with ex
In C++, a dynamic array can be created using a smart pointer such as 
std::unique_ptr or std::shared_ptr.

For example, the following code creates a dynamic array of integers using 
std::unique_ptr:

Copy code
#include <iostream>
#include <memory>

int main() {
    std::unique_ptr<int[]> ptr(new int[5]);
    ptr[0] = 1;
    ptr[1] = 2;
    ptr[2] = 3;
    ptr[3] = 4;
    ptr[4] = 5;
    std::cout << "Array: [";
    for (int i = 0; i < 5; i++) {
        std::cout << ptr[i] << " ";
    }
    std::cout << "]" << std::endl;
    return 0;
}

In this example, the program creates a std::unique_ptr smart pointer ptr that
points to an array of 5 integers allocated with new[] operator. The program then
assigns values to the elements of the array and prints them.

When the ptr goes out of scope, the destructor of std::unique_ptr is called, 
which calls the delete[] operator on the pointer to free the memory of the array.

It's also possible to use std::shared_ptr to create a dynamic array, here's an
example:

Copy code
#include <iostream>
#include <memory>

int main() {
    std::shared_ptr<int[]> ptr(new int[5]);
    ptr[0] = 1;
    ptr[1] = 2;
    ptr[2] = 3;
    ptr[3] = 4;
    ptr[4] = 5;
    std::cout << "Array: [";
    for (int i = 0; i < 5; i++) {
        std::cout << ptr[i] << " ";
    }
    std::cout << "]" << std::endl;
    return 0;
}
The main difference between std::unique_ptr and std::shared_ptr is that
std::unique_ptr can only be owned by one owner, while std::shared_ptr can have
multiple owners.

It's worth noting that std::unique_ptr and std::shared_ptr are not able to resize
the allocated memory, if you need to resize the array, you should create a new 
array and copy the elements from the old array to the new one, and then use the
smart pointer to manage the new array.

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: