KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am looking for an efficient way of either trimming or copying a subset of an existing std::vector. The criteria for elements to be eligible for the subset / remain is that their index is contained in a separate predefined std::vector. e.g std::vector<String> Test = { "A", "B", "C", "D", "E"} std::vector<int> SelectionV = {1,2,5} Result = {"A", "B", "E"} I will be doing this on a very large vector and probably on a regular basis, so am looking for as efficient method as possible. An alternative that I am also considering, but again unsure of an efficient method is... As the object Test is filled (in my case it is 3rd party defined object), it is the result of a single pass through using an iterator (no direct element access is possible). I was wondering if instead it is possible to only add to the Test vector elements that appear in the count defined in SelectionV e.g int count = 0 for (Iterator.begin, Iterator.end(), Iterator++) { if (count is a number contained in selectionV) add to Test } but I assume that will result in a pass through the selectionV on each iteration, which would be far less efficient than simply adding all elements and later selecting a subset. Any help much appreciated.
Tags (comma-separated)
Save Edits
Cancel