3

So let's say I have an

std::vector<int> myVector;

and a function

myFunction(std::vector<int> parameter); 

I want to be able to pass a subvector of myVector to myFunction without having to copy the elements over into a new vector first. Can this be done?

billz
  • 44,644
  • 9
  • 83
  • 100
user1855952
  • 1,515
  • 5
  • 26
  • 55

1 Answers1

1

Make your function take iterator range instead, for example:

template< class Iterator, class T >
void myFunction( Iterator first, Iterator last, const T& value );
billz
  • 44,644
  • 9
  • 83
  • 100