#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 < std:: vector < listA> > listOfItems1;
std:: vector < std:: vector < listB> > listOfItems2;
int main( )
{
std:: vector < int > listB:: * pList = & listB:: listOfToys ;
genericFoo( listOfItems2, pList) ;
return 0 ;
}
I2luY2x1ZGUgPHZlY3Rvcj4KCnRlbXBsYXRlIDx0eXBlbmFtZSBUb3BDb250YWluZXIsIHR5cGVuYW1lIFRvcEVsZW1lbnQsIHR5cGVuYW1lIEJvdHRvbUNvbnRhaW5lcj4Kdm9pZCBnZW5lcmljRm9vKGNvbnN0IFRvcENvbnRhaW5lciYgdG9wTGlzdCwgQm90dG9tQ29udGFpbmVyIFRvcEVsZW1lbnQ6OiogYm90dG9tTGlzdCkgCnsKICAgIGZvciAoYXV0byBpdCA9IHRvcExpc3QuYmVnaW4oKTsgaXQgIT0gdG9wTGlzdC5lbmQoKTsgKytpdCkgewogICAgICAgIC8vIC4uLgogICAgICAgIGNvbnN0IEJvdHRvbUNvbnRhaW5lciYgbGlzdDIgPSAoKml0KS4qYm90dG9tTGlzdDsKICAgICAgICBmb3IgKGF1dG8gaXQyID0gbGlzdDIuYmVnaW4oKTsgaXQyICE9IGxpc3QyLmVuZCgpOyArK2l0MikgewogICAgICAgICAgICAvLyBkbyBzb21lIHN0dWZmCiAgICAgICAgfQogICAgfQp9CgpzdHJ1Y3QgbGlzdEEgewogICAgc3RkOjp2ZWN0b3I8Y2hhcj4gbGlzdE9mQXBwbGVzOyAgICAKfTsKCnN0cnVjdCBsaXN0QiB7CiAgICBzdGQ6OnZlY3RvcjxpbnQ+IGxpc3RPZlRveXM7Cn07CgpzdGQ6OnZlY3Rvcjwgc3RkOjp2ZWN0b3I8bGlzdEE+ID4gbGlzdE9mSXRlbXMxOwpzdGQ6OnZlY3Rvcjwgc3RkOjp2ZWN0b3I8bGlzdEI+ID4gbGlzdE9mSXRlbXMyOwoKICAgIAppbnQgbWFpbigpCnsKICAgIHN0ZDo6dmVjdG9yPGludD4gbGlzdEI6OipwTGlzdCA9ICZsaXN0Qjo6bGlzdE9mVG95czsKICAgIGdlbmVyaWNGb28obGlzdE9mSXRlbXMyLCBwTGlzdCk7CiAgICByZXR1cm4gMDsKfQ==
compilation info
prog.cpp: In function 'void genericFoo(const TopContainer&, BottomContainer TopElement::*) [with TopContainer = std::vector<std::vector<listB> >, TopElement = listB, BottomContainer = std::vector<int>]':
prog.cpp:30:35: instantiated from here
prog.cpp:8:47: error: pointer to member type 'std::vector<int>' incompatible with object type 'std::vector<listB>'
stdout