KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a std::vector with n elements. Now I need to pass a pointer to a vector that has the last n-1 elements to a function. For example, my vector<int> foo contains (5,2,6,87,251) . A function takes vector<int>* and I want to pass it a pointer to (2,6,87,251) . Can I just (safely) take the iterator ++foo.begin() , convert it to a pointer and pass that to the function? Or use &foo[1] ? UPDATE: People suggest that I change my function to take an iterator rather than a pointer. That seems not possible in my situation, since the function I mentioned is the find function of unordered_set<std::vector*> . So in that case, is copying the n-1 elements from foo into a new vector and calling find with a pointer to that the only option? Very inefficient! It's like Shlemiel the painter, especially since i have to query many subsets: the last n-1 , then n-2 , etc. elements and see if they are in the unordered_set .
Tags (comma-separated)
Save Edits
Cancel