Reputation: 11
Is there any possible way to pass pointer to a double (double *
) as argument to a function which expects a reference to a std::vector<double>
argument in C++11
Upvotes: 1
Views: 197
Reputation: 63152
Rather than copying the data into a vector, you could also change the function to take a span
. You will still have to include the length along with the pointer.
void takes_span(std::span<double>) {}
int main()
{
std::vector<double> vec = { 1, 2, 3 };
double arr[3] = { 4, 5, 6 };
double * ptr = arr;
takes_span(vec);
takes_span(arr);
takes_span({ptr, 3});
}
Upvotes: 1