Assuming a function needs a pointer to a vector of type T but when I have only a vector of vector of type T(type is not guaranteed to be a POD), is this
std::vector<std::vector<T>> input;
auto selectedVectorPtr=&input[j];
safer than this
std::vector<std::vector<T>> input;
auto selectedVectorPtr=&(input[j]);
also assuming input's scope doesn't end until that function which takes selectedVectorPtr
as parameter.
My concerns(/misconceptions) are:
operator[]
has higher precedence then operator&
(postfix operators have the highest precedence), so it is evaluated first here, no parenthesis needed. There is no difference between &input[j]
and &(input[j])
here.
Alternative simpler syntax:
auto selectedVectorPtr = input.data() + j;
No need for std::addressof
here either.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With