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()), bitend(baselist.end()); MemberList::iterator mit(memberlist.begin()), mitend(memberlist.end()); 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; }
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; }