/* * Run with * * -i iterations * * to do a stress test for the given number of iterations. * * -p * * to print correct output. */ #include #include #include #include #include #include #include #include #include #include #include "Map.hpp" /* * Wrapper class around std::map to handle slight difference in return value and also * provide an Iterator nested name. */ template class test_map : public std::map { private: using base_t = std::map; public: using Iterator = typename base_t::iterator; std::pairinsert(const std::pair &p) { return this->base_t::insert(p); } }; /* * Person class. */ struct Person { friend bool operator<(const Person &p1, const Person &p2) { return p1.name < p2.name; } friend bool operator==(const Person &p1, const Person &p2) { return p1.name == p2.name; } Person(const char *n) : name(n) {} void print() const { printf("Name: %s\n", name.c_str()); } const std::string name; Person &operator=(const Person &) = delete; }; void print(const std::pair &p) { p.first.print(); printf(" %d\n", p.second); } /* * MyClass class. */ struct MyClass { friend bool operator<(const MyClass &o1, const MyClass &o2) { return o1.num < o2.num; } friend bool operator==(const MyClass &o1, const MyClass &o2) { return o1.num == o2.num; } MyClass(double n) : num(n) {} double num; }; void print(const std::pair &p) { printf("%d, %s; ", p.first, p.second.c_str()); } /* * Stress class. */ struct Stress { friend bool operator<(const Stress& o1, const Stress& o2) { return o1.val < o2.val; } friend bool operator==(const Stress& o1, const Stress& o2) { return o1.val == o2.val; } Stress(int _v) : val(_v){} int val; }; // Helper function for stress testing. This orders iterators by what they point to. template