Is there a C++ (preferably C++11) standard-compliant idiom which I can employ to allow a std::vector<double>
to borrow the contents of a double[]
of known size?
I have a function (actually a functor masquerading as a callback from an optimiser) with prototype:
double MyFunctorClass::operator()(double s[]) const;
(MyFunctorClass
also has m_size
which reveals the number of elements of s
).
I want to call a function that takes a const std::vector<double>&
as an input.
One solution technique involves my creating a std::vector<double>
member variable and somehow switching the double[]
data into the data area of that std::vector
, call the function, then switch it back to the caller. I'd rather not copy due to performance concerns: it is the objective function. Any ideas?