Can I convert std::vector
element pointer to index with this?
http://coliru.stacked-crooked.com/a/cedf3d849539e001
template<class T>
std::size_t get_index(std::vector<T>& vec, T* ptr){
const std::size_t i = ptr - &(*vec.begin());
return i;
}
If elements in vector is guaranteed to be contiguous, then I think we can do such pointer arithmetic... Or no?