There's a guideline saying that one single function should have one single responsibility. But, oftentimes I come across with a problem: I should search through a large container(it can be a two-dimensional container, each item of each is a container itself) and to collect found into, say, a vector.
In addition, I should get the first index of occurrence, nth, last, in worst case some of these altogether.
Things get more complicated if I should search by several criteria and to collect what's found in correspondent vector.
Is Single Responsibility Rule still applicable to this kind of situation?
Should the return type of my function be a tuple of some kind?
Should I pass parameters by non-const references?
I'd like to know how do you guys treat this situation in the real world.
It's simply not always possible to meet that criterion.
For example, suppose that you want to find all the elements in a sequence that are divisible by 7, and also all the ones that are less than 42. But you don't know the sequence, because it's coming from a stream that can't be rewinded, and you can't hold it anywhere because it's too large.
The only option in this scenario is to write a single loop that does both data collections at once.
Although if you can use coroutines, you can write the code as if you had two separate functions that read from two separate streams