I have a vector<int>
and functions that only accepts a vector<unsigned int>
references.I know that I could change/template the functions(and this is likely the best thing to do), but ideally I would have a way to cast/convert the vector<unsigned int>
reference to a vector<int>
reference. I know that all values in the vector are positive, and non of the functions will even come close to overflowing the integers.
I have tried using static_cast<vector<int>>
but that doesn't work.
Edit:
I say cast/convert of the references but I am not looking to create a new copy and reference that.
std::vector<unsigned int>
to begin with, no copying or conversion needed.vector<unsigned int>
is bad by design. At least, the function should be a function template, where the vector value type is a template parameter. Even a better approach would be to use iterators as input parameters, or something asstd::span
.