Question: In c++, Write a templated function (named make_double) that takes two arguments: An array pointer reference of a templated type A size_t reference which is
In c++, Write a templated function (named "make_double") that takes two arguments:
An array pointer reference of a templated type
A size_t reference which is the size of the array
This function should make the array pointer reference point at a new dynamic array that is twice the size and has two copies of each original value in the array. It should also make the sz reference have the double size.
// Example usecase: #includeusing std::copy; #include using std::vector; size_t sz = 3; long * ary_ptr = new long[sz]{1, 2, 3}; make_double(ary_ptr, sz); ASSERT_EQ(6, sz); vector expected{1, 2, 3, 1, 2, 3}; vector result(sz); copy(ary_ptr, ary_ptr + sz, result.begin()); ASSERT_EQ(expected, result);
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
