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
  • 43,318
  • 8
  • 77
  • 98
user1855952
  • 1,447
  • 5
  • 26
  • 53

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
  • 43,318
  • 8
  • 77
  • 98