|
-
December 19th, 2012, 03:24 AM
#5
Re: Passing a sub-range of a vector by reference
 Originally Posted by ejohns85
So I'm wondering if it is possible to directly pass a sub-range of my_vector by reference, without having to create a new vector and manually copy over all of the relevant elements?
You could pass a start-of-range iterator and a range length to the function. The function can then use the iterator for either sequential or random access to the elements within the range.
More ambitious would be to introduce a class called say Subrange which is used to access a vector subrange while hiding the details. A Subrange object would then be passed to the function. Clean, simple, safe and efficient (at least potentially ).
Last edited by nuzzle; December 19th, 2012 at 07:31 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|