I'm writing a library function that takes a list (or bunch) of items (let's say Student) and does something with them. What's the best way to write the function signature in the interface?std::vector<Student> The problem with the is that maybe my caller isn't using STL and then they need to instantiate and populate a vector. Not clean and performance suffers.Student* + numOfStudents doesn't seem right, this isn't C.A function taking a begin and end iterator? Should it then be implemented as a template function?
How should I write an interface that takes a list of items?
c++;interfaces
If the goal is to accept as many different types of list as possible, then you should write a template function that accepts anything, and in your implementation either use the begin() and end() free functions to get iterators for it, or use a foreach loop (which the compiler will implement for you using begin() and end()).This will work for raw arrays, all standard container classes, and all non-standard container classes emulating the standard container interface. In fact, that level of generic-ness is exactly why begin() and end() free functions were added to the language.If you really need to accept anything, you can still provide additional overloads that take a begin and an end iterator or a pointer and a length.