I am creating a function titled linspase
with C++17 with the following input structure linspace(double upper, double lower, int size)
. The function should create size
evenly spaced numbers between lower
and upper
. Programming this function is easy; however, I want it to create an std::array<double, size>
where the function will determine the array size from the function call and pass back the data type std::array<double, size>
. I know templates are the only way to do this, but I am not sure how to build the template. In a general pseudo code I think it looks something like this.
template <typedef T, size_t size>
T linspace(double lower, double upper, int num)
{
/* ... Function meat goes here to create arr of size
num of evenly space numbers between lower and upper
*/
return arr
}
However, I know this template declaration is not right and I am not sure what it is supposed to look like. To be clear, I want it to return an std:;array
of a specific size, not an std::vector
.