#ifndef TRACER_H_ #define TRACER_H_ #include #include #include // This class is useful when you are exploring the behavior of STL // containers. The class gives each instance that is manufactured // using the default constructor a unique ID and an ID "history": // the chain of IDs that led to this current one. // // Whenever an object is manufactured using the copy constructor, its // history is copied from the argument. Similarly, whenever an object // is the target of an assignment operator, then its history is copied // from the source. Then, the current Tracer's ID is appended to this // history // // Finally, object instances print messages out whenever important events // happen, including default construction, copy construction, // destruction, assignment, and "less than" operator invocation. // (Less than is used as a comparator for things like sorting or // inserting into the right sorted spot in a map.) class Tracer { public: // Constructors. Tracer(); ~Tracer(); Tracer(const Tracer &rhs); // Assignment operator. Tracer &operator=(const Tracer &rhs); // Less-than comparison operator. bool operator<(const Tracer &rhs) const; // << operator friend std::ostream &operator<<(std::ostream &out, const Tracer &rhs); private: // Return "id_ [history_]" as a string std::string Print(void) const; // This static (class member) tracks the next id_ to hand out. static int nextid_; const int id_; // fixed id of this Tracer int value_; // the most recent id that set this Tracer's value }; #endif // TRACER_H_