/////////////////////////////////////////////////////////////////// // pair.cpp - demonstrate use of pair type from STL // // // // Jim Fawcett, CSE687 - Object Oriented Design, Spring 2001 // /////////////////////////////////////////////////////////////////// #include #include #include #include using namespace std; //----< create string representation of template type >-------- template string formatElement(Elem &elem) { string retString; if(typeid(Elem) == typeid(string)) { retString = "\""; retString += elem; retString += "\""; return retString; } ostringstream retStream; retStream << elem; return retStream.str(); } //----< create string representation of pair >----------------- template string format(const pair &pr) { string retStr = "pair<"; retStr += formatElement(pr.first); retStr += " : "; retStr += formatElement(pr.second); retStr += ">"; return retStr; } //----< test pair operations >--------------------------------- void main() { cout << "\n Demonstrate use of pair type " << "\n ==============================\n"; pair psi("string argument",-7); cout << "\n " << format(psi); pair pds(3.1415927,"another string argument"); cout << "\n " << format(pds); cout << "\n\n"; }