BaseList<KEYTYPE>* FileSave::GetAllKeys() { BaseList<KEYTYPE>* keys = new BaseList<KEYTYPE>(); auto it = this->list->GetContainer()->begin(); while (it != this->list->GetContainer()->end()) { Pair<KEYTYPE, GenType*>* value = (*it); keys->Add(value->Item1); it++; } return keys; }
bool simple_slist_test() { //Define an slist that will store MyClass using the public base hook typedef any_to_slist_hook< base_hook< any_base_hook<> > >BaseOption; typedef slist<MyClass, BaseOption, constant_time_size<false> > BaseList; //Define an slist that will store MyClass using the public member hook typedef any_to_slist_hook< member_hook<MyClass, any_member_hook<>, &MyClass::member_hook_> > MemberOption; typedef slist<MyClass, MemberOption> MemberList; typedef std::vector<MyClass>::iterator VectIt; typedef std::vector<MyClass>::reverse_iterator VectRit; //Create several MyClass objects, each one with a different value std::vector<MyClass> values; for(int i = 0; i < 100; ++i) values.push_back(MyClass(i)); BaseList baselist; MemberList memberlist; //Now insert them in the reverse order in the base hook list for(VectIt it(values.begin()), itend(values.end()); it != itend; ++it) baselist.push_front(*it); //Now insert them in the same order as in vector in the member hook list for(BaseList::iterator it(baselist.begin()), itend(baselist.end()) ; it != itend; ++it) { memberlist.push_front(*it); } //Now test lists { BaseList::iterator bit(baselist.begin()); MemberList::iterator mit(memberlist.begin()); VectRit rit(values.rbegin()), ritend(values.rend()); VectIt it(values.begin()), itend(values.end()); //Test the objects inserted in the base hook list for(; rit != ritend; ++rit, ++bit) if(&*bit != &*rit) return false; //Test the objects inserted in the member hook list for(; it != itend; ++it, ++mit) if(&*mit != &*it) return false; } return true; }
int main() { typedef std::vector<MyClass>::iterator VectIt; typedef std::vector<MyClass>::reverse_iterator VectRit; //Create several MyClass objects, each one with a different value std::vector<MyClass> values; for(int i = 0; i < 100; ++i) values.push_back(MyClass(i)); BaseList baselist; MemberList memberlist; //Now insert them in the reverse order in the base hook list for(VectIt it(values.begin()), itend(values.end()); it != itend; ++it) baselist.push_front(*it); //Now insert them in the same order as in vector in the member hook list for(BaseList::iterator it(baselist.begin()), itend(baselist.end()) ; it != itend; ++it){ memberlist.push_front(*it); } //Now test lists { BaseList::iterator bit(baselist.begin()); MemberList::iterator mit(memberlist.begin()); VectRit rit(values.rbegin()), ritend(values.rend()); VectIt it(values.begin()), itend(values.end()); //Test the objects inserted in the base hook list for(; rit != ritend; ++rit, ++bit) if(&*bit != &*rit) return 1; //Test the objects inserted in the member hook list for(; it != itend; ++it, ++mit) if(&*mit != &*it) return 1; } return 0; }
// a little demonstration how this works static void ListGetNextDemo() { BaseList<DemoListNode> test; // just append a few nodes test.Append(); test.Append(); test.Append(); test.Append(); test.Append(); // old style iterate over a list using GetNext(): this is SLOWER than using an iterator VLONG cntA = 0; for (DemoListNode* node = test.GetFirst(); node; node = node->GetNext()) { node->_a = 1; node->_b = 2; cntA++; } // iterate over a list using Iterator - a little bit more to write VLONG cntB = 0; for (BaseList<DemoListNode>::Iterator it = test.Begin(); it != test.End(); it++) { it->_a = 3; it->_b = 4; cntB++; } // iterate over a list using AutoIterator VLONG cntC = 0; for (AutoIterator<BaseList<DemoListNode> > it(test); it; it++) { it->_a = 5; it->_b = 6; cntC++; } if ((cntA != cntB) || (cntA != cntC)) GeBoom(); }
int main() { { // Create an empty list BaseList<int> mylist; // make sure the size is null assert(mylist.len() == 0); // now we prepend some items mylist.prepend(3); mylist.prepend(2); mylist.prepend(1); // now let's append some items mylist.append(4); mylist.append(5); // check the size again cout << mylist.len()<< endl; assert(mylist.len() == 5); // make sure the first one is correct assert(mylist.get(0) == 1); // make sure the 3rd one is correct assert(mylist[2] == 3); // make sure the last one is correct assert(mylist.get(mylist.len() - 1) == 5); // now let's delete stuff mylist.del(4); mylist.insert(3, 9); BaseList<int>::Iterator iter = mylist.begin(); *iter = 9; listprint(mylist); mylist.print(); BaseList<int> newlist; mylist = newlist; } // test iterator cout << "All tests passed! YAY Everything works!" << endl << "You're f*****g amazing. Go get yourself some drinks." << endl; return 0; }
void listprint(BaseList<int> list) { list.print(); }