#include <vector>

template <typename TopContainer, typename TopElement, typename BottomContainer>
void genericFoo(const TopContainer& topList, BottomContainer TopElement::* bottomList) 
{
    for (auto it = topList.begin(); it != topList.end(); ++it) {
        // ...
        const BottomContainer& list2 = (*it).*bottomList;
        for (auto it2 = list2.begin(); it2 != list2.end(); ++it2) {
            // do some stuff
        }
    }
}

struct listA {
    std::vector<char> listOfApples;    
};

struct listB {
    std::vector<int> listOfToys;
};

std::vector<listA> listOfItems1;
std::vector<listB> listOfItems2;

    
int main()
{
    std::vector<int> listB::*pList = &listB::listOfToys;
    genericFoo(listOfItems2, pList);
    return 0;
}