Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started