CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Threaded View

  1. #5
    Join Date
    May 2009
    Posts
    2,413

    Re: Passing a sub-range of a vector by reference

    Quote Originally Posted by ejohns85 View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured