Q:

How to combine two codes into one function?

My code creates arrays, I need to implement deletions for it, but I don’t know how to do it beautifully and correctly.
main code
template<class T1>
auto auto_vector(T1&& _Size) {
    return new int64_t[_Size]{};
}
template <class T1, class... T2>
auto auto_vector(T1&& _Size, T2&&... _Last)
{
    auto result = new decltype(auto_vector(_Last...))[_Size];
    for (int64_t i = 0; i < _Size; ++i) {
        result[i] = auto_vector(_Last...);
    }
    return result;
}

this is the code that I want to combine with the first
template <class T1, class T2, class T3, class T4>
void del_vector(T4& _Del, T1& _Size, T2& _Size2, T3& _Size3) {
    for (ptrdiff_t i = 0; i < _Size3; ++i) {
        for (ptrdiff_t k = 0; k < _Size2; ++k) {
            delete _Del[i][k];
        }
        delete _Del[i];
    }
    delete _Del;
}
int main()
{
    auto map1 = auto_vector(_Size, _Size2, _Size3);

    auto map2 = auto_vector(3, 4, 5, 7);

    del_vector(map1, _Size, _Size2, _Size3);

    return 0;
}

I do not like this option I would like something like that.
int main()
{
    auto_vector map1(_Size, _Size2, _Size3);

    del_vector map1(_Size, _Size2, _Size3);

    //or so

    auto_vector<_Size, _Size2, _Size3> map1;

    del_vector<_Size, _Size2, _Size3> map1;

    return 0;
}

the reason why I do this is because I cannot implement the same thing using just a vector
and I don’t understand why the vector does not work with dynamic arrays, the fact is that I do not know the exact data
_Size, _Size2, _Size3 = ? before compilation.
therefore I use new and all this I do only for his sake.
if it is useful to you to look at the data for tests
cout << " ---------TEST---------- " << endl;
    for (ptrdiff_t i = 0; i < _Size3; ++i) {
        for (ptrdiff_t k = 0; k < _Size2; ++k) {
            for (ptrdiff_t j = 0; j < _Size; ++j) {
                cout << map1[i][k][j] << " ";
            }
            cout << endl;
        }
        cout << endl;
    }
    cout << " ---------TEST---------- " << endl;

A:

You have too many new operations in the code. Also del_vector doesn't make any sense in your preferred version as any decent class will deallocate its data in the destructor (lest it has no ownership over it).
What you need is to make a class or a template class that wraps things up.
#include <iostream>
#include <vector>
#include <array>
#include <type_traits>

using namespace std;

template<size_t index, size_t dim>
void ModifyArray(std::array<size_t,dim>& lcAarray){}

template<size_t index, size_t dim, typename... Args>
void ModifyArray(std::array<size_t, dim>& lcAarray, size_t arg, Args... args)
{
    lcAarray[index] = arg;
    ModifyArray<index+1>(lcAarray, args...);
}

template<typename... Args>
std::array<size_t, sizeof...(Args)> MakeArray(Args... args)
{
    std::array<size_t, sizeof...(Args)> lclArray;
    ModifyArray<0>(lclArray, args...);
    return lclArray;
}

template< std::size_t dim > 
class myMultiArray;

template<std::size_t dim, std::size_t crDim>
class MyMultiArrayIterator
{
    public:
    MyMultiArrayIterator(myMultiArray<dim>* multiArray, size_t index):
        m_pMultiArray(multiArray),
        m_index(index)
    {}

    template<size_t newDim = crDim+1,  typename std::enable_if<newDim < dim, int>::type = 0>
    MyMultiArrayIterator<dim, newDim> operator [] (size_t idx)
    {
        return MyMultiArrayIterator<dim, newDim>(m_pMultiArray, m_index + idx*m_pMultiArray->GetStep(crDim));
    }

    template<size_t newDim = crDim+1,  typename std::enable_if<newDim == dim, int>::type = 0>
    int& operator [] (size_t idx)
    {
        return m_pMultiArray->GetValue(m_index+idx*m_pMultiArray->GetStep(crDim));
    }

    private:
    size_t              m_index;
    myMultiArray<dim>*  m_pMultiArray;
};

template< std::size_t dim > 
class myMultiArray
{
public:
    myMultiArray() = default;

    template<class... Args, typename std::enable_if<sizeof...(Args) == dim-1, int>::type = 0>
    myMultiArray(size_t size0, Args... args)
    {
        m_sizes = MakeArray(size0, args...);

        std::size_t uTotalSize = 1;
        for (std::size_t i = 0; i < dim; i++)
        {
            m_steps[i] = uTotalSize;
            uTotalSize *= m_sizes[i];
        }
        std::cout  << uTotalSize << "\n";
        m_data.resize(uTotalSize);
     }
     // resizes m_data to multiplication of sizes
     int operator  () (std::array < std::size_t, dim > indexes) const
     {
        return m_data[computeIndex(indexes)];
     }
     int &operator  () (std::array < std::size_t, dim > indexes)
     {
        return m_data[computeIndex(indexes)];
     }
     // modify operator
     // you'll probably need more utility functions for such a multi dimensional array

     int GetValue(size_t index) const
     {
        return m_data[index];
     }

     int &GetValue(size_t index)
     {
        return m_data[index];
     }

     size_t GetSize(size_t index) const
     {
         return m_sizes[index];
     }

     size_t GetStep(size_t index) const
     {
         return m_steps[index];
     }

     MyMultiArrayIterator<dim, 1> operator [] (size_t index)
     {
         return  MyMultiArrayIterator<dim, 1>(this, index*m_steps[0]);
     }

private:
     size_t computeIndex(std::array < std::size_t, dim > indexes)
     {
       size_t location = 0;
       for(size_t i=0; i< dim; i++)
       {
           location += m_steps[i]*indexes[i];
       }
       return location;
    }

private:
    std::vector < int >             m_data;
    std::array < std::size_t, dim > m_sizes;
    std::array < std::size_t, dim > m_steps;
};

template<typename... Args>
myMultiArray<sizeof...(Args)> MakeMyMultiArray(Args... args)
{
    return myMultiArray<sizeof...(Args)>(args...);
}

int main ()
{
    auto mapMA = MakeMyMultiArray(3,4,5);

    mapMA({2ull,3ull,4ull}) = 7;
    std::cout << mapMA({{2ull,3ull,4ull}})  << "\n";
    std::cout << mapMA[2][3][4];
  return 0;
}

