C++ (Qt)struct CBigClass {... QList<CData> mData; QSet<CData *> mSelection; ...};
C++ (Qt)void CBigClass::SomeMethod( void ) { .. for (auto & data : mData) { ... }}
C++ (Qt)void CBigClass::SomeMethod2( void ) { .. for (auto it : mSelection) { ... }}
for (auto it = std::begin(container); it != std::end(container); ++it)
C++ (Qt)void CBigClass::SomeMethod( bool useSelection ) { .. int limit = useSelection ? mSelection.size() : mData.size(); auto dataIt = mData.begin(); auto selIt = mSelection.begin(); for (int i = 0; i < limit; ++i) { CData * dataPtr; if (useSelection) { dataPtr = *selIt; ++selIt; } else { dataPtr = &(*dataIt); ++dataIt; } ... }}
C++ (Qt)template<class Iter>CData & DataRef( Iter & it ){ return *it;} CData & DataRef( QSet<CData *>::iterator & it ){ return *(*it);}
C++ (Qt)template<class Container>void CBigClass::SomeMethod( Container & container ) { ... for (auto it = container.begin(); it != container.emd(); ++it) { CData & data = DataRef(it); ... }}
template<typename T>void iterateContainer(const T& t){ for (auto it = std::begin(t); it != std::end(t); ++it) { // do something }}void testIterate(){ std::vector<int> vec; std::list<int> list; std::map<int, std::string> map; iterateContainer(vec); iterateContainer(list); iterateContainer(map);}
template<typename T>void iterateContainer(const T& t){ for (auto it = std::begin(t); it != std::end(t); ++it) { // do something }}}
C++ (Qt)template<class T>CData & DataRef( T & ref ) { return ref; } CData & DataRef( CData *& refPtr ) { return *refPtr; }